Variables

Server configuration and request information—including form parameters and cookies—are accessible in three different ways from your PHP scripts, as described in this section. Collectively, this information is referred to as EGPCS (environment, GET, POST, cookies, and server).

If the register_globals option in php.ini is enabled (it is disabled by default), PHP creates a separate global variable for every form parameter, every piece of request information, and every server configuration value. This functionality is convenient but dangerous, as it lets the browser provide initial values for any of the variables in your program. The (negative) effects this can have on your program’s security are explained in Chapter 12.

Regardless of the setting of register_globals, PHP creates six global arrays that contain the EGPCS information.

The global arrays are:

$_COOKIE

Contains any cookie values passed as part of the request, where the keys of the array are the names of the cookies

$_GET

Contains any parameters that are part of a GET request, where the keys of the array are the names of the form parameters

$_POST

Contains any parameters that are part of a POST request, where the keys of the array are the names of the form parameters

$_FILES

Contains information about any uploaded files

$_SERVER

Contains useful information about the web server, as described in the next section

$_ENV

Contains the values of any environment variables, where the keys of the array are the names of the environment ...

Get Programming PHP, 2nd 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.