CGI Operation
CGI program response and Name/Value pairs
Describes how the common gateway interface operates. Data sent from forms, as you can see from the example on the previous page, has the following characteristics:
- Information is sent in the form of a name and value pair.
- Each name/value pair begins with an & sign.
- The name/value pair are seperated by the equals (=) sign between the name and the value.
- They are URL encoded.
URL encoding changes some characters to placeholders and substitutes a hexadecimal ASCII value for some characters. To process the data in the server follow this sequence:
- Get the data from the proper variable depending on whether the POST or GET method was used.
- Change any placeholders to their correct values (Change any + signs to spaces).
- Split each group of name value pairs into an array of strings.
- Convert hexadecimal values back to ASCII character equivalents.
- Evaluate the respective names and values.
See the "Poll Receiving" section of the Perl manual in this CGI section for an example of this process.
Responding to the Client
Any output to be returned to the client web browser can be sent to the standard output of the CGI program as in the following line:
print "Content-type: text/html", "\n\n<P>This will appear on the clients' web browser.</P>"; # MIME header.
Two blank lines must be placed after the parsed header.
The CGI application must send a parsed header to it's standard output which is intercepted by the web server. From the parsed header, the web server will create the required non-parsed HTTP response header to be sent to the client. The parsed header must contain a server directive which may include one or more of:
- Content-type - Indicates the MIME type of the data being sent back to the client.
- Location - The URL the client web browser should be directed to.
- Status - A HTTP status code. Common codes are 200 (OK) and 404 (not found).
|