next up previous contents
Next: URL Encoding Up: HTTP Headers Previous: HTTP Headers

CGI and Environment Variables

You are already familiar with environment variables from Chapter  12. When your CGI program is started, the Web server creates and initializes a number of environment variables that your program can access using the %ENV hash.

Below we give a short description of each environment variable. A complete description of the environmental variables used in CGI programs can be found at

-- Optionally provides the authentication protocol used to access your script if the local Web server supports authentication and if authentication was used to access your script.
-- Optionally provides the length, in bytes, of the content provided to the script through the STDIN file handle. Used particularly in the POST method of form processing. See next Chapter for more information.
-- Optionally provides the type of content available from the STDIN file handle. This is used for the POST method of form processing. Most of the time, this variable will be blank and you can assume a value of application/octet-stream.
-- Provides the version of CGI supported by the local Web server. Most of the time, this will be equal to CGI/1.1.
-- Provides a comma-separated list of MIME types the browser software will accept. You might check this environmental variable to see if the client will accept a certain kind of graphic file.
-- Provides the user's e-mail address. Not all Web browsers will supply this information to your server. Therefore, use this field only to provide a default value for an HTML form.
-- Provides the type and version of the user's Web browser. For example, the Netscape Web browser is called Mozilla.
-- Optionally contains any extra path information from the HTTP request that invoked the script.
-- Maps the script's virtual path (i.e., from the root of the server directory) to the physical path used to call the script.
-- Optionally contains form information when the GET method of form processing is used. QUERY_STRING is also used for passing information such as search keywords to CGI scripts.
-- Contains the dotted decimal address of the user.

-- Optionally provides the domain name for the site that the user has connected from.

-- Optionally provides client identification when your local server has contacted an IDENTD server on a client machine. You will very rarely see this because the IDENTD query is slow.

-- Optionally provides the name used by the user to access your secured script.

-- Usually contains either "GET" or "POST"-the method by which form information will be made available to your script. See next Chapter for more information.

-- Contains the virtual path to the script.
-- Contains the configured hostname for the server.
-- Contains the port number that the local Web server software is listening on. The standard port number is 80.
-- Contains the version of the Web protocol this server uses. For example, HTTP/1.0.

-- Contains the name and version of the Web server software. For example, WebSite/1.1e.

next up previous contents
Next: URL Encoding Up: HTTP Headers Previous: HTTP Headers