Web-Related Variables
PHP automatically creates
variables for all the data it receives in an HTTP request. This can
include GET data, POST data, cookie data, and environment variables.
The variables are either in PHP’s global symbol
table or in one of a number of superglobal arrays, depending on the
value of the register_globals
setting in your
php.ini file.
Beginning with PHP 4.2.0, the default
setting for register_globals
is
off
. With register_globals
off,
all the various variables that are usually available directly in the
global symbol table are now available via individual superglobal
arrays. There is a limited set of superglobals and they cannot be
created from a user-level script. The superglobal array to use
depends on the source of the variable. Here is the list:
-
$_GET
GET-method variables. These are the variables supplied directly in the URL. For example, with http://www.example.com/script.php?a=1&b=2,
$_GET['a']
and$_GET['b']
are set to 1 and 2, respectively.-
$_POST
POST-method variables. Form field data from regular POST-method forms.
-
$_COOKIE
Any cookies the browser sends end up in this array. The name of the cookie is the key and the cookie value becomes the array value.
-
$_REQUEST
This array contains all of the above variables (i.e., GET, POST, and cookie). If a variable appears in multiple sources, the order in which they are imported into
$_REQUEST
is given by the setting of thevariables_order
php.ini directive. The default is'GPC'
, which means GET-method ...
Get Webmaster in a Nutshell, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.