Skip to content

How to Use $_SERVER['QUERY_STRING'] Properly in PHP


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 Chinese words (it means Taiwan).


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.