Previous Section  < Day Day Up >  Next Section

6.1 Useful Server Variables

Aside from PHP_SELF, the $_SERVER auto-global array contains a number of useful elements that provide information on the web server and the current request. Table Table 6-1 lists some of them.

Table 6-1. Entries in $_SERVER






The part of the URL after the question mark where the URL parameters live. The example query string shown is for the URL



Extra path information tacked onto the end of the URL after a slash. This is a way to pass information to a script without using the query string. The example PATH_INFO shown is for the URL


The name of the web site on which the PHP interpreter is running. If the web server hosts many different virtual domains, this is the name of the particular virtual domain that is being accessed.



The directory on the web server computer that holds the documents available on the web site. If the document root is /usr/local/htdocs for the web site, then a request for corresponds to the file /usr/local/htdocs/catalog/store.php.


The IP address of the user making the request to your web server.


If your web server is configured to translate user IP addresses into hostnames, this is the hostname of the user making the request to your web server. Because this address-to-name translation is relatively expensive (in terms of computational time), most web servers do not do it.


If someone clicked on a link to reach the current URL, HTTP_REFERER contains the URL of the page that contained the link. This value can be faked, so don't use it as your sole criteria for giving access to private web pages. It can, however, be useful for finding out who's linking to you.


Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

The web browser that retrieved the page. The example value is the signature of Internet Explorer 6.0 running on Windows XP. Like HTTP_REFERER, this value can be faked, but is useful for analysis.

[2] The correct spelling is HTTP_REFERRER. But it was misspelled in an early Internet specification document, so you frequently see the three-R version when web programming.

    Previous Section  < Day Day Up >  Next Section