Environment Variables

The environment variables contain useful information — some regarding the web browser and machine of the client accessing the CGI script — which the program can access. There are a few very important environment variables, and many that exist but are rarely used [because they are rarely useful].

Accessing environment variables is a very system- and language-specific matter, and it is the programmer's responsibility to do this correctly. However, the names and content of the environment variables are standard.

QUERY_STRING

The data following the '?' in a form submitted with the "METHOD=get" attribute.

CONTENT_LENGTH

The length of the data waiting on standard input for POSTed forms.

REQUEST_METHOD

The method by which the CGI data was submitted [ie: "GET" or "POST"]. There are other request methods, but GET and POST are the two most common.

REMOTE_HOST

The name of the machine from which the client is accessing the form. If the client machine is using a proxy to access the web, then this will be the name of the proxy host. If there does not exist a hostname for the client's machine, this will be unset.

REMOTE_ADDR

The IP address of the client machine. This should be the IP address which the hostname given in REMOTE_HOST will decode to [ie: they should be the same machine]. If the client machine is using a proxy to access the web, this will be the IP address of the proxy machine.

REMOTE_USER

If the user had to go through authentication to get to the script, then this will be the login with which they authenticated.

HTTP_USER_AGENT

A string describing the web browser which the client is using. This string will generally follow the format "browser/version extra_info". For instance: "Mozilla/4.5 [en] (X11; I; Linux 2.0.32 i586)" [Mozilla means Netscape — Remember: it's spelled N-E-T-S-C-A-P-E, but it's pronounced "mozilla"].