Every time you request a Web page, an immense amount of activity takes place behind the scenes: your request is sent to a DNS server, an IP address is found, the corresponding Web server is contacted, and the resulting data stream is decoded and rendered by your Web browser as an HTML page. In addition to the actual HTML content requested, however, the Web server also includes a number of important "server variables" in its response. These variables contain information about both the Web server environment - its name, IP address and software - and the current script execution environment - the script name and path and the query string.
These variables are often used by clever Web developers to make their scripts more dynamic and robust. This document outlines (Table A) some of the more useful server variables that a Web server typically sends out when it responds to an HTTP request, and also explains when and how you could use each one on your Web site.
Note:Some of these variables may not be available in all Web servers.
For more information on these and other server variables, consider taking a look at the CGI 1.1 specification.
Table A
Variable
What It Contains
What It's Useful For
HTTP_USER_AGENT
An identification string sent by the client making the request. For example: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5.
Client detection and logging; creating code that works differently in different browsers.
HTTP_ACCEPT_ENCODING
The list of encodings the client is able to decode.
Improving transfer speeds by using GZIP encoding (for example) to compress page data.
REMOTE_ADDR
The IP address of the client making the request.
Obtaining the user's geographical location for targeted advertising or localized information retrieval; restricting access to specific IP addresses or groups of IP addresses.
DOCUMENT_ROOT
The server's document root directory (as defined in its configuration).
Constructing relative/absolute paths when uploading, copying or moving files through a Web application.
SERVER_SOFTWARE
The server's signature, indicating the name and version of the server as well as any software running on it. For example: Apache/2.0.55 (Win32).
Identifying server capabilities.
QUERY_STRING
The list of variable-value pairs that follow the "?" in the requested URL.
Retrieving and parsing the variable-value pairs sent to the server via its URL.
REQUEST_METHOD
The method used to make the URL request. For example GET, POST or PUT.
Identifying the method used to request the page, and thereby accessing the appropriate namespace for variable retrieval.
SCRIPT_NAME
The server path to the requested resource (relative to the document root).
Retrieving the name and path to the currently-executing script or resource.
HTTP_ACCEPT_CHARSET
The character sets the client is able to receive.
Sending page data in a preferred character set.
REMOTE_USER
When using HTTP authentication, the username supplied for authentication.
Content personalization; credential verification.