CGI Environment Variables
browser info | form info | program info | server info | visitor identity
Program and Form Information
- SCRIPT_NAME
- The virtual path of the CGI script relative to DOCUMENT_ROOT. It can be used in conjunction with
DOCUMENT_ROOT to determine the physical disk location of the program or with SERVER_NAME to
determine the URL of the program. For example:
$prg_location = "$ENV{'DOCUMENT_ROOT'}$ENV{'SCRIPT_NAME'}";
$prg_url = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";
Example: '/cgi-bin/myscript.cgi' - REQUEST_METHOD
- POST or GET
- CONTENT_LENGTH
- For forms submitted with POST, the number of bytes in the standard input. You can then read the attached
data from STDIN. (numeric)
Example: 382 - CONTENT_TYPE
- In a form submitted with POST, the MIME content type of the form data. In forms submitted with POST the value will be "application/x-www-form-urlencoded". In forms with file upload, the content-type will be "multipart/form-data".
- QUERY_STRING
- The arguments to the script. For forms submitted with GET, the form input. Bascially everything after the ? in the URL. There is a limit to how much info can be passed with GET. The amount varies from server to server.
- PATH_INFO
- Extra path information, as sent by the browser. For example:
http://www.domain.com/cgi-bin/myscript.cgi/users/username
PATH_INFO would be set to '/users/username' - PATH_TRANSLATED
- The actual system-specific pathname of the path contained in PATH_INFO. This variable treats PATH_INFO as a
relative path within your server's Web space and turns it into a full, absolute path on your server's hard drive.
Example: '/home/users/tina'
Visitor Identity and Browser Request Information
- REMOTE_ADDR
- The visitor's IP address. (string)
Example: '100.100.100.100' - REMOTE_HOST
- The visitor's host name. Usually the same as the visitor's domain name, but some servers may
set this variable to the visitor's IP address or even leave it empty. Note: this variable cannot be set.
Example: 'domain.com' - REMOTE_USER
- The username of the visitor that called the script. This value will only be set if server authentication is turned on.
- REMOTE_IDENT
- If the web server is running Ident (a protocol to verify the user connecting to you) and the system that submitted the form or script is also running Ident, this variable contains the value returned by Ident.
- HTTP_USER_AGENT
- The browser that submitted the form. Usually includes the browser name, version number, and info about the
visitor's operating system.
Example: 'Mozilla/4.0 (Macintosh; I; PPC)' - HTTP_ACCEPT
- A list of content-types that the browser can accept directly, as defined by the HTTP Accept header. Basically, a list
of the MIME types supported by the visitor's browser. Usually only contains an abbreviated list.
Example: 'image/gif, image/jpeg' - HTTP_REFERER
- If the CGI script was called from a link within a Web page, the complete URL of the referring page. If a form
submission, the URL of document that sent the form data, though not all browsers send this value.
Example: 'http://www.domain.com/myform.html' - HTTP_COOKIE
- The value of any cookies that have been set in the visitor's browser and which are accessible by your site.
- SERVER_PROTOCOL
- The name and revision of the request protocol used to access the server. The HTTP protocol that the server
is running.
Example: 'HTTP/1.1' - SERVER_PORT
- The TCP port on which the server is running. The port to which the program was sent.
Usually port 80 for web servers.
Example: 80
Server Information
- SERVER_NAME
- Host name or IP address on which the CGI script is running, as it appears in the URL.
- SERVER_SOFTWARE
- The name and version of the Web server software.
Example: 'NCSA/1.5.2' - GATEWAY_INTERFACE
- The version of CGI running on the server.
- DOCUMENT_ROOT
- The absolute path of the root directory for the server. This is the directory that the server's domain name maps to.
- SERVER_ADMIN
- The email address for the server administrator.

