DelphiFAQ Home Search:

What kind of environment variables does a web context provide?


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

There are three classes of environment variables:

  1. Server specific environment variables
  2. Script specific environment variables
  3. Request specific environment variables (read from the headers)

Server specific environment variables

The first group of environment variables are server-specific and be the same value for any request.

Variable Name Description Example
SERVER_SOFTWARE The name and version of the server software answering the HTTP request. Apache/2.0
SERVER_NAME The server hostname. This could also be the DNS alias or IP address. MACHINE_42
GATEWAY_INTERFACE The CGI revision that this server complies with. CGI/1.1

Script specific environment variables

The next group of environment variables are specific to the script, so expect them to vary.

Variable Name Description Example
SERVER_PROTOCOL The name and version number of the protocol that called the script. HTTP/1.0
SERVER_PORT The port number for the script. 80
REQUEST_METHOD The method for the CGI request. GET (or POST, or HEAD)
PATH_INFO Any extra path information that follows the script path in the URL. If present, it is passed as an argument to the script. For instance, http://hostname/cgi-bin/EnvVars.cgi/PathInfo /PathInfo
PATH_TRANSLATED A virtual-to-physical mapping of PATH_INFO, which can be used directly as an absolute path or file. hostname\cgi-bin\PathInfo
SCRIPT_NAME A virtual path to the script. Useful if you output HTML code that refers back to the script. /cgi-bin/EnvVar.cgi
QUERY_STRING A key variable when using METHOD=GET from your web page. It contains the information following '?' in the URL, and passes it to the script. For instance, http://hostname/cgi-bin/EnvVars.cgi?QueryString QueryString
REMOTE_HOST The hostname making the request. If it is not available, then the IP address should be in REMOTE_ADDR. This value isn't always set.
REMOTE_ADDR The IP address of the client making the request.
AUTH_TYPE The protocol-specific authentication method used to validate users. Only used if the server supports authentication. (varies)
REMOTE_USER If the server supports authentication, and the script is protected, then this value will hold the username of the individual. (varies)
REMOTE_IDENT This variable is used solely for logging, if the HTTP server supports RFC 931 identification. In those cases, it will be set to the remote user name.  
CONTENT_TYPE For requests made with METHOD=POST, this will be the content type of the data.  
CONTENT_LENGTH The length in bytes of the content being passed (set by the client).  

Environment variables from header lines

These variables are set if there were header lines received from the browser.

Variable Name Description Example
HTTP_ACCEPT The MIME types the client will accept. 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*'
HTTP_USER_AGENT The browser that the client is using. This is useful if you want to present browser specific pages to your users. If the user has installed additional tools like the Yahoo companion, you'll see that in this field as well. (Internet Explorer 4.0): Mozilla/4.0 (compatible; MSIE 4.01; Windows 2000;)


2006-05-15, 05:30:25
anonymous from India  
I find $ENV{HTTP_REFERENCE} not working
2006-05-15, 14:14:35
anonymous from United States  
Note that HTTP_REFERER is written with a single R at the end.. not *REFERRER



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: