C or C++ | #include <stdlib.h>
char *browser = getenv("HTTP_USER_AGENT");
|
Perl | $browser = $ENV{` HTTP_USER_AGENT'};
|
Bourne shell | BROWSER=$ HTTP_USER_AGENT
|
C shell | set BROWSER = $ HTTP_USER_AGENT
|
AUTH_TYPE:
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 an AOLserver, this is always "Basic
".
CONTENT_LENGTH:
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 QUERY_STRING: for details about the format of the contents of standard input and Accessing Standard Input for examples that read from standard input.)
CONTENT_TYPE:
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.
GATEWAY_INTERFACE:
The version number of the CGI specification this server supports.
HTTP_ACCEPT:
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
HTTP_FROM:
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.
HTTP_IF_MODIFIED_SINCE:
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
HTTP_REFERER:
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
HTTP_USER_AGENT:
This variable tells which browser the reader is using to send the request. Normally, the format is "browser name/version".
Mozilla/1.2N (Windows; I; 16bit)
PATH_INFO:
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
Examples: /misc/mydir
/keyword=navigate
PATH_TRANSLATED:
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
QUERY_STRING:
This variable contains information passed by a form or link to the program. The QUERY_STRING contains information in the following situations:
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 CGI Examples for a list of Web sites containing such functions.) The string encoding follows these rules:
Figfield.x=185&Figfield.y=37
# -- %23 | = -- %3D
| / -- %2F
|
% -- %25 | : -- %3A
| \ -- %5C
|
& -- %26 | ; -- %3B
| tab -- %0A
|
+ -- %2B | ? -- %3F
| return -- %09
|
REMOTE_HOST:
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.
REMOTE_USER:
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.
REQUEST_METHOD:
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.
SCRIPT_NAME:
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.
SERVER_NAME:
The full hostname, domain name alias, or IP address of the server that ran the CGI program.
128.111.115.9
SERVER_PORT:
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.
SERVER_PROTOCOL:
The name and version number of the information protocol used to pass this request from the client to the server.
SERVER_SOFTWARE:
The name and version number of the server software running the CGI program.
Other Environment Variables:
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 Configuring CGI with an AOLserver).
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.