Standard environment variables
The following are some of the more standard CGI environment variables. Note that:
- Some of these environment variables may not be supported by your server;
- Even if some of these environment variables are supported by your server, they may be implemented differently; and
- Your server may support more environment variables than those listed here.
To find out what environment variables your server does support, and how it implements them, take a look at the environment variables CGI example.
Server Specific Environment Variables
DOCUMENT_ROOT
- Absolute path on server machine of root web folder (e.g.
/usr/httpd/htdocs/
) GATEWAY_INTERFACE
- Version of CGI supported by the server (e.g.
CGI/1.1
) SERVER_ADDR
- IP address of the server
SERVER_ADMIN
- Email address of server administrator
SERVER_NAME
- Host name of the server (e.g.
www.paulgriffiths.net
) SERVER_PORT
- Listening port of the server (usually
80
) SERVER_PROTOCOL
- Name and version of protocol used by the server (e.g.
HTTP 1/1
) SERVER_SOFTWARE
- Name (and version, usually) of server software (e.g.
Apache/2.2.4
)
Request Specific Environment Variables
AUTH_TYPE
- Type of authentication used by the server (e.g.
basic
) CONTENT_LENGTH
- Number of characters passed to
STDIN
from aPOST
request (e.g.220
) CONTENT_TYPE
- Type of data sent to the server, if applicable (e.g.
application/x-www-form-urlencoded
) HTTP_REFERER
- URI of web page that called the script
PATH_INFO
- Relative path information included in the URI after
the script name, but before the query string (e.g. if http://www.paulgriffiths.net/cgi-bin/envvars.pl/more/path/info?var1=red&var2=herring
is called then
PATH_INFO
would contain/more/path/info
). PATH_TRANSLATED
- Same as
PATH_INFO
but with the virtual path translated into an absolute path on the server machine, i.e. not a URI (e.g./usr/httpd/htdocs/more/path/info/
) QUERY_STRING
- The part of the URI after the ? character (e.g.
var1=red&var2=herring)
) REMOTE_ADDR
- User's IP address
REMOTE_PORT
- User's port
REMOTE_USER
- User's identified name, if authorisation was used.
REQUEST_METHOD
- The HTTP request method used, usually
GET
orPOST
, but can be different. REQUEST_URI
- Full relative URI of request (e.g.
/cgi-bin/envvars.pl/more/path/info?var1=red&var2=herring
) SCRIPT_NAME
- Name of script before any additional path info or query string (e.g.
/cgi-bin/envvars.pl
) SCRIPT_FILENAME
- Absolute path on the server machine of the script (e.g.
/usr/httpd/htdocs/cgi-bin/envvars.pl
)
Client Specific Environment Variables
HTTP_ACCEPT
- File types accepted by the client (e.g.
text/xml,application/xml,application/xhtml+xml,text/html,image/png,*/*
) HTTP_USER_AGENT
- Name and version of client software (e.g.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
)