Skip to content
Home » Web » PHP » How to Use $_SERVER['QUERY_STRING'] Properly

How to Use $_SERVER['QUERY_STRING'] Properly


Let's see a snippet of PHP code, which will generate three similar output:

echo $_SERVER['QUERY_STRING'] . "<br />";
echo urldecode($_SERVER['QUERY_STRING']) . "<br />";
echo $_GET['a'];

Then, we test the page by clicking the URL with a query string containing two multibyte words.


The output is:



As you can see, $_GET is already url-decoded, but $_SERVER['QUERY_STRING'] is not. Therefore, if you insist to use $_SERVER['QUERY_STRING'], you have to urldecode() the string before using it. Otherwise, you will meet unexplained errors in multilingual websites.

Leave a Reply

Your email address will not be published. Required fields are marked *