CGI programs can get input from these sources:
Different languages allow you to access environment variables in different ways. Here are some examples:
These standard environment variables are defined for all CGI programs by the AOLserver:
If the server supports user authentication, and the script is protected, this is the protocol-specific authentication method used to validate the user. For CGI programs run by AOLserver, this is always "Basic
".
If the CGI program is run by a form with the POST method, this variable contains the length of the contents of standard input in bytes. There is no null or EOF character at the end of standard input, so in some languages (such as C and Perl) you should check this variable to find out how many bytes to read from standard input. (See page 111 for details about the format of the contents of standard input and page 114 for examples that read from standard input.)
If the CGI program is run by a form with the POST method, this variable contains the MIME type of the information sent by the browser. Currently, all browsers should send the information as application/x-www-form-urlencoded
. Other types may be added in the future.
The version number of the CGI specification this server supports.
A comma-separated list of the MIME types the browser will accept, as specified in the HTTP header the browser sends. Many browsers do not send complete lists, and the list does not include external viewers the user has installed. If you want to send browser-specific output, you may also want to check the browser name, which is specified by the HTTP_USER_AGENT variable.
Examples: */*, application/x-navidoc
*/*, image/gif, image/x-xbitmap, image/jpeg
This variable may contain the email address of the reader who caused the CGI program to run. However, some browsers do not send the email address for privacy reasons. And, users may enter false email addresses in their preferences settings.
Example: [email protected]
This variable contains a date and time if the browser wants a response only if the data has been modified since the specified date and time. The date is in GMT standard time. Many browsers do not send this information.
Example: Thursday, 23-Nov-95 17:00:00 GMT
This variable contains the URL of the page or other location from which the reader sent the request to run the CGI program. For example, if the reader runs the program from a form, this variable contains the URL of that form.
Example: http://www.mydomain.com/mydir/feedback.htm
This variable tells which browser the reader is using to send the request. Normally, the format is "browser name/version".
Example: Mozilla/1.2N (Windows; I; 16bit)
This variable contains any extra path information included in the URL sent by the browser. Commonly, this type of URL is used to pass a relative directory location to your program. For example, the following URL runs the listdir
program and passes it /misc/mydir
as extra path information:
http://www.mysite.com/cgi-bin/listdir/misc/mydir
Another use for this type of URL is to pass information to the program without using a form or to pass form-specific variables in addition to the user-specified variables. For example:
http://www.mysite.com/cgi-bin/search/keyword=navigate
/keyword=navigate
This variable translates the relative path from PATH_INFO into the absolute path by prepending the server's root directory for Web documents. This is useful because PATH_INFO, which the reader can view, need not reveal the physical location of your files on the server.
Example: /
AOLserver/pages/misc/mydir
This variable contains information passed by a form or link to the program. The QUERY_STRING contains information in the following situations:
The QUERY_STRING is encoded in a format like this:
Field1=Value1&Field2=Value2&Field3=Value3
Your CGI program should decode the QUERY_STRING. Functions that decode this string are publicly available functions for most languages. (See page 118 for a list of Web sites containing such functions.) The string encoding follows these rules:
Figfield.x=185&Figfield.y=37
The IP address of the machine from which or through which the browser is making the request. This information is always available.
The full domain name of the machine from which or through which the browser is making the request. If this variable is blank because the browser did not send the information, use the REMOTE_ADDR variable instead.
If the server prompted the reader for a username and password because the script is protected by the AOLserver's access control, this variable contains the username the reader provided.
The method used to send the request to the server. For direct links, the method is "GET". For requests from forms, the method may be "GET" or "POST". Another method is "HEAD", which CGI programs can treat like "GET" or can provide header information without page contents.
The virtual path to the CGI script or program being executed from the URL used to execute the script. You may want to use this variable if the program generates a page that contains a form that can be used to run the program again -- for example, to search for another string.
The full hostname, domain name alias, or IP address of the server that ran the CGI program.
128.111.115.9
The server port number to which the request was sent. This may be any number between 1 and 65,535 (that is not already a well-known port). The default is 80.
The name and version number of the information protocol used to pass this request from the client to the server.
The name and version number of the server software running the CGI program.
In addition to the preceding environment variables, the HTTP header lines received from the client, if any, are placed into the environment with the prefix HTTP_ followed by the header name. Any spaces in the header name are changed to underscores (_). The server may exclude any headers it has already processed, such as Content-type, and Content-length.
Also, you can specify environment variables to be passed to a CGI program in the AOLserver configuration file (see page 105).
If a form uses the POST method to send a request, the field names and values are sent to standard input and the length of this string is provided in the CONTENT_LENGTH environment variable. The format of the standard input string is the same as the format of the QUERY_STRING environment variable when the GET method is used (see page 111).
Different languages allow you to access the standard input in different ways. Here are some simplified examples. Your programs should also do some error checking.