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 http://www.ast.cam.ac.uk/drtr/cgi-spec.html

AUTH_TYPE
-- 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.
CONTENT_LENGTH
-- 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.
CONTENT_TYPE
-- 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.
GATEWAY_INTERFACE
-- Provides the version of CGI supported by the local Web server. Most of the time, this will be equal to CGI/1.1.
HTTP_ACCEPT
-- 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.
HTTP_FORM
-- 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.
HTTP_USER_AGENT
-- Provides the type and version of the user's Web browser. For example, the Netscape Web browser is called Mozilla.
PATH_INFO
-- Optionally contains any extra path information from the HTTP request that invoked the script.
PATH_TRANSLATED
-- Maps the script's virtual path (i.e., from the root of the server directory) to the physical path used to call the script.
QUERY_STRING
-- 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.
REMOTE_ADDR
-- Contains the dotted decimal address of the user.

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

REMOTE_IDENT
-- 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.

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

REQUEST_METHOD
-- 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.

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

SERVER_SOFTWARE
-- 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
dave@cs.cf.ac.uk