Visit the Official PHP Website
Search this Site

PHP Programming

By James N Hitz

Predefined Variables

PHP sports a function called phpinfo(). When called this function answers by giving a comprehsensive list of all Predefined Variables.

Pre-defined variables are variables all-right but they are special variables in that they are defined by PHP during the execution time of any PHP script. These variables are many and varied and largely depend on the server configuration.

The common ones (assuming you are running Apache 1.3.6) are:

SERVER_NAME:This gives the name of the server host under which the current script is executing.
SERVER_SOFTWARE:Server identification string, given in the headers when responding to requests.
REQUEST_METHOD:Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
QUERY_STRING:The query string, if any, via which the page was accessed.
DOCUMENT_ROOT:The document root directory under which the current script is executing, as defined in the server's configuration file.
HTTP_REFERER:The address of the page (if any) which referred the browser to the current page. This is set by the user's browser; not all browsers will set this.
REMOTE_ADDR:The IP address from which the user is viewing the current page.
SCRIPT_FILENAME:The absolute pathname of the currently executing script.
PATH_TRANSLATED:Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.
SCRIPT_NAME:Contains the current script's path. This is useful for pages which need to point to themselves.
REQUEST_URI:The URI which was given in order to access this page; for instance, '/index.html'.

A long list this one is but it does not even try to exhaust all the predefined variables. Let's use PHP's phpinfo() function to see all the pre-defined variables in your server.

<< Type Juggling Clowns | phpinfo() in Action >>