CGI Variables

CGI Environment variables are the main source of information which your server side scripts can use.

  • AUTH_TYPE - Describes the authentication method used by the web browser if any authentication method was used. This is not set unless the script is protected.
  • CONTENT_LENGTH - This is used for scripts that are receiving form data using the POST method. This variable tells the byte length of the CGI input data stream. This is required to read the data from the standard input with the POST method.
  • CONTENT_TYPE - Tells the media type of data being received from the user. this is used for scripts called using the POST method.
  • DOCUMENT_ROOT - The root path to the home HTML page for the server. Example:


  • GATEWAY_INTERFACE - The version of the common gateway interface (CGI) specification being used to exchange the data between the client and server. this is normally CGI/1.1 for the current revision level of 1.1. Example:


  • PATH_INFO - Extra path information added to the end of the URL that accessed the server side script program.
  • PATH_TRANSLATED - A translated version of the PATH_INFO variable translated by the webserver from virtual to physical path information.
  • QUERY_STRING - This string contains any information at the end of the server side script path that followed a question mark. Used to return data if the GET method was used by a form. There are length restrictions to the QUERY_STRING. Example of how to set it in HTML:

    <A HREF="/cgi-bin/></A>

    The information after the ? is the QUERY_STRING which is "mainpage" in this case. How it looks on the server side


  • REMOTE_ADDR - The IP address of the client computer. Example:

  • REMOTE_HOST - The fully qualified domain name of the client machine making the HTTP request. It may not be possible to determine this name since many client computers names are not recorded in the DNS system. Example:

  • REMOTE_IDENT - The ability to use this variable is limited to servers that support RFC 931. This variable may contain the client machine's username, but it is intended to be used for logging purposes only, when it is available.
  • REMOTE_PORT - The clients requesting port. An example:


  • REMOTE_USER - If the CGI script was protected and the user had to be logged in to get access to the script, this value will contain the user's log in name
  • REQUEST_URI - The path to the requested file by the client. An example:


  • REQUEST_METHOD - This describes the request method used by the browser which is normally GET, POST, or HEAD.
  • SCRIPT_NAME - The virtual path of the CGI script being executed. Example:


  • SCRIPT_FILENAME - Example:


  • SERVER_ADMIN - The e-mail address of the server administrator. Example:

  • SERVER_NAME - The server hostname, IP address or DNS alias name shown as a self referencing URL. This does not include the protocol identifier such as "HTTP:", the machine name, or port number. Example:


  • SERVER_PORT - The port number the HTTP requests and responses are being sent on. Example:


  • SERVER_PROTOCOL - This value is normally HTTP which describes the protocol being used between the client and server computers. Example:


  • SERVER_SIGNATURE - Server information specifying the name and version of the web server and the port being serviced. Example:

    Apache/1.3.12 Server at mdct-dev3 Port 80

  • SERVER_SOFTWARE - The name and version of the web server. Example:

    Apache/1.3.12 (Unix) (Red Hat/Linux) PHP/3.0.15 mod_perl/1.21

  • HTTP_ACCEPT - The media types of data that the client browser can accept. these data types are separated by commas. An example:

    image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/, application/msword, application/, */*


    gzip, deflate

  • HTTP_ACCEPT_LANGUAGE - The language the client browser accepts. Example:


  • HTTP_COOKIE - Used as an environment variable that contains cookies associated with the server domain from the browser.
  • HTTP_FORWARDED An example:

    by (Netscape-Proxy/3.5)

  • HTTP_HOST An example:

  • HTTP_PRAGMA - An example:


  • HTTP_REFERER - The page address where the HTTP request originated. An example:

  • HTTP_USER_AGENT - The name of the client web browser being used to make the request. Example:

    Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)