Using the Common Gateway Interface

The cgi Interface

The common gateway interface is the link between the web server and other programs on the system. CGI programs must be stored in directories specified in the server configuration (/web/cgi-bin/ for www.mcm.edu) or have particular extensions (.cgi for www.mcm.edu) and be written to work with the interface. The Perl language is popular for this purpose. Another popular approach is to use a server-side scripting language such as PHP.

We can interface in two ways:

GET
sends information by appending it to the url.

Example: http://cs1.mcm.edu/cgi-bin/test-cgi?one+two+three. This simple encoding is used for files with an <isindex> tag in the <Head> and may also be used in forms

POST
sends data via standard input. The use of POST rather than GET is indicated in three ways:
  1. method header: REQUEST_METHOD=POST
  2. Content-type: application/x-www-form-urlencoded
  3. Content-length: indicates the length of the data

Encoding Form Data

Data sent from a form is typically encoded as name=value pairs separated by & as in
email_name=rob&my_name=Robert


cgi-lib.pl is a Perl library that assists in decoding and processing form data. It is rather outdated today and has been replaced with CGI.pm and old scripts really should be updated. This Feedback Form and its associated script illustrate this and this Big form and the printall script demonstrate both form elements and processing.

Guides | HTML Primer | Form Overview

Search |  Computer Science |  Feedback
Site Map