O'Reilly logo

PHP in a Nutshell by Paul Hudson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Superglobals

Variables that come into PHP arrive inside one of several special arrays known collectively as the superglobals , so named because they are available throughout your script, even inside objects and other arrays. Superglobals include form data sent from your visitor, cookie data, session information, local server information, and more, making them good to keep around. Superglobals were not available in PHP prior to v4.1, but there were older alternatives that provided much of the functionality. Superglobals are superior, though, so it is recommended that all new scripts use them.

There are nine superglobal arrays available for use, categorized by type of variable. These are shown in Table 5-2.

Table 5-2. The superglobal arrays

Name

Functionality

$_GET

Contains all variables sent via a HTTP GET request. For example, a URL of myfile.php?name=Paul would load myfile.php and give you $_GET["name"] with the value "Paul". Users of older PHP versions will have used $HTTP_GET_VARS array, which, although deprecated, is still available for use.

$_POST

Contains all variables sent via a HTTP POST request. This is similar to the old $HTTP_POST_VARS array, which, although deprecated, is still available for use.

$_FILES

Contains all variables sent via a HTTP POST file upload. This is similar to the old $HTTP_POST_FILES array, which is also deprecated.

$_COOKIE

Contains all variables sent via HTTP cookies. This is similar to the old $HTTP_COOKIE_VARS array, which is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required