I have a rather strange problem. I created a simple php script that generates a form with the GET method and just one box for anyone to type anything in. then below that, the server environment variables are listed.
When I click the submit button, I'm supposed to see QS=Q=x
where x is the text I type in and the first array from print_r is supposed to contain the index Q being equal to x.
The problem is, no matter what I type in, $_SERVER['QUERY_STRING']
is never populated and print_r($_GET);
always outputs an empty array.
Why is this happening and how do I fix it?
<?php
echo "<!DOCTYPE HTML><html><head><title>Test</title></head><body>";
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"GET\">";
echo "<input type=\"text\" name=\"Q\"><input type=\"submit\">";
echo "</form>";
echo "<h1>QS=".$_SERVER['QUERY_STRING']."</h1>";
echo "<pre>";
print_r($_GET);
print_r($_SERVER);
echo "</pre>";
echo "</body></html>";
exit();
?>
Nevermind... I found the answer
I had the following in my .htaccess file which trimmed all the query strings from the requests.
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1? [R=301,L]
I now removed it and everything works.