05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The global arrays are:<br />

$HTTP_COOKIE_VARS<br />

Contains any cookie values passed as part of the request, where the keys of the<br />

array are the names of the cookies<br />

$HTTP_GET_VARS<br />

Contains any parameters that are part of a GET request, where the keys of the<br />

array are the names of the form parameters<br />

$HTTP_POST_VARS<br />

Contains any parameters that are part of a POST request, where the keys of the<br />

array are the names of the form parameters<br />

$HTTP_POST_FILES<br />

Contains information about any uploaded files<br />

$HTTP_SERVER_VARS<br />

Contains useful information about the web server, as described in the next section<br />

$HTTP_ENV_VARS<br />

Contains the values of any environment variables, where the keys of the array are<br />

the names of the environment variables<br />

Because names like $HTTP_GET_VARS are long and awkward to use, <strong>PHP</strong> provides<br />

shorter aliases: $_COOKIE, $_GET, $_POST, $_FILES, $_SERVER, and $_ENV. These variables<br />

are not only global, but also visible from within function definitions, unlike their<br />

longer counterparts. These short variables are the recommended way to access EGPCS<br />

values. The $_REQUEST array is also created by <strong>PHP</strong> if the register_globals option is<br />

on; however, there is no corresponding $HTTP_REQUEST_VARS array. The $_REQUEST<br />

array contains the elements of the $_GET, $_POST, and $_COOKIE arrays.<br />

<strong>PHP</strong> also creates a variable called $<strong>PHP</strong>_SELF, which holds the name of the current<br />

script, relative to the document root (e.g., /store/cart.php). This value is also accessible<br />

as $_SERVER['<strong>PHP</strong>_SELF']. This variable is useful when creating self-referencing<br />

scripts, as we’ll see later.<br />

Server Information<br />

The $_SERVER array contains a lot of useful information from the web server. Much of<br />

this information comes from the environment variables required in the CGI specification<br />

(http://hoohoo.ncsa.uiuc.edu/cgi/env.html).<br />

Here is a complete list of the entries in $_SERVER that come from CGI:<br />

SERVER_SOFTWARE<br />

A string that identifies the server (e.g., “Apache/1.3.22 (Unix) mod_perl/1.26<br />

<strong>PHP</strong>/4.1.0”).<br />

160 | Chapter 7: Web Techniques<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!