|CGI Environment Variables|
When a browser invokes a CGI program, the web server software provides certain environment information to the CGI program. In Perl, this information is available via the %ENV associative array / hash. The exact variables that are available will vary depending on the Web server software being used, but the following is a representative list from Apache.
The authentication method used to validate a user. Ex.REMOTE_USER or REMOTE_IDENT.
The length of the query data (in bytes or the number of characters)passed to the CGI program through standard input.
The media type of the query data, such as "text/html."
The directory from which Web documents are served.
The revision of the Common Gateway Interface that the server uses.
A list of the media types that the client can accept.
The email address of the user making the query (many browsers do not support this variable).
The URL of the document that the client points to before accessing the CGI program.
The browser the client is using to issue the request.
Extra path information passed to a CGI program.
The translated version of the path given by the variable PATH_INFO.
The query information passed to the program. It is appended to the URL following a question mark (?).
The remote IP address from which the user is making the request.
The remote hostname from which the user is making the request. Only available if the web server performs reverse lookups on client requests. For performance reasons, this is typically not done.
The user making the request. Not typically used or available. This variable depends on the use of the "ident" feature of the web server.
The authenticated name of the user making the query. Available if the web server required a user name and password for the page.
The method with which the information request was issued (e.g., GET,POST, HEAD).
The virtual path (e.g., /cgi-bin/program.pl) of the script being executed.
The server's hostname or IP address.
The port number of the host on which the server is running.
The name and revision of the information protocol the request came in with.
The name and version of the server software that is answering the client request.
The variables REQUEST_METHOD, CONTENT_LENGTH, and QUERY_STRING are important for processing user input. The variable HTTP_USER_AGENT can be important if a program is customizing it's output for specific browsers.
The following program will dump out the environment variables passed to a CGI program.
Copyright 2001 - Andy Welter