Environment variables


SERVER_NAME The host name (or the IP address) where the script is running.
SERVER_SOFTWARE The server software used. Examples: CERN/3.0 or NCSA/1.3
GATEWAY_INTERFACE CGI version running on the server
SERVER_PROTOCOL Used HTTP protocol version. It should be CGI/1.1
SERVER_PORT TCP port to which the server is connected to. Usually its value is 80
REQUEST_METHOD The used method: GET or POST
HTTP_ACCEPT A Content-type list the browser can handle
HTTP_USER_AGENT The browser's name that sent information. This variable usually contains the browser's name, its version number and other information such as the platform where it is running
HTTP_REFERER The URL of the document which contains the form
PATH_INFO The URL and additional information sent by the browser when the GET method is used (see Dissecting the simplest CGI script: Hello Net! for more information)
PATH_TRANSLATED The real system's path contained inside of PATH_INFO variable
SCRIPT_NAME The script's name and the path
QUERY_STRING Information sent by means of the GET method. In other words all information sent after the '?' symbol inside of the URL
REMOTE_HOST The host name which sent the request
REMOTE_ADDR The host address which sent the request
REMOTE_USER The user name of who sent the request (when an authentication is available)
REMOTE_IDENT The server name which sent the request (when the ident protocol is available)
CONTENT_TYPE When the POST method is used, its value is: 'application/x-www-form-urlencoded'. When a file is sent, its value is: 'multipart/form-data'
CONTENT_LENGTH When the POST method is used, its value define the input standard size. In other words the number of bytes sent

A simple CGI script to show environment variables

#!/usr/bin/perl
# Filename: vars.perl.cgi
# Send the MIME header
print "Content-type: text/plain\n\n";

# CGI standard variables
print "GATEWAY_INTERFACE = $ENV{'GATEWAY_INTERFACE'}\n";
print "REQUEST_METHOD = $ENV{'REQUEST_METHOD'}\n";
print "SCRIPT_NAME = $ENV{'SCRIPT_NAME'}\n";
print "QUERY_STRING = $ENV{'QUERY_STRING'}\n";
print "SERVER_SOFTWARE = $ENV{'SERVER_SOFTWARE'}\n";
print "SERVER_NAME = $ENV{'SERVER NAME'}\n";
print "SERVER_PROTOCOL = $ENV{'SERVER_PROTOCOL'}\n";
print "SERVER_PORT = $ENV{'SERVER_PORT'}\n";
print "HTTP_USER_AGENT = $ENV{'HTTP_USER_AGENT'}\n";
print "HTTP_ACCEPT = $ENV{'HTTP_ACCEPT'}\n";
print "PATH_INFO = $ENV{'PATH_INFO'}\n";
print "PATH_TRANSLATED = $ENVI{'PATH_TRANSLATED'}\n";
print "REMOTE_HOST = $ENV{'REMOTE HOST'}\n";
print "REMOTE_ADDR =$ENV{'REMOTE_ADDR'}\n";
print "REMOTE_USER = $ENV{'REMOTE_USER'}\n";
print "REMOTE_IDENT = $ENV{'REMOTE_IDEN'}\n";
print "AUTH_TYPE = $ENV{'AUTH_TYPE'}\n";
print "CONTENT_TYPE = $ENV{'CONTENT_TYPE'}\n";
print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n";


Index           Home  Back       About  Contact us!

Copyright (c) 1998-2006 Wowarea