Entry
why is $_GET always an empty list ?
Dec 8th, 2002 21:20
Philip Olson, Jens Clasen, nick name,
Several reasons could exist, such as:
a) You are using a PHP version prior to PHP 4.1.0 as
superglobals (autoglobals) such as $_GET were introduced
at this time:
http://www.php.net/release_4_1_0.php
http://www.php.net/manual/en/language.variables.predefined.php
For older versions of PHP, use $HTTP_GET_VARS.
b) There is no GET information. An example of GET is either through an
HTML form that has method="GET" or if you have a QUERY_STRING
within the URL (stuff after the ?), such as:
http://www.example.com/foo.php?fruit=apple&color=red
print $_GET['fruit']; // apple
print $_GET['color']; // red
See also: http://www.php.net/variables.external
c) Typo or misunderstanding. A good way to test exactly what
information lives within a variable is to use var_dump() or
print_r() which will show you content (arrays as well) and
type of any var:
var_dump($_GET);
d) Put a call to phpinfo() within the script getting the GET
information. phpinfo() will list all received vars as well.
And for your information, GET information also lives in the $_REQUEST
autoglobal. $_REQUEST (as described in the manual) is a mix of GET,
POST and COOKIE information and was also introduced in PHP 4.1.0.
autoglobals are preferred over relying on the register_globals PHP
directive.