Introduction to CGI

Information from the browser and some from the HTTP server is submitted to CGI programs via environment variables or on the standard input. Any language that provides access to environment variables and standard input/output may be used to write CGI programs.

If the submission method is GET, the QUERY_STRING environment variable is delivered with urlencoded variables. This string must be decoded.

If the form method is POST, exactly $CONTENT_LENGTH bytes must be read from the standard input and urldecoded.

At a minimum, on the standard output for delivery to the browser must be:

Content-type: text/html
or
Location: url
followed by a blank line, followed by html or nothing (in the case of a Location: redirect).

The Location: redirect is useful in implementing security by returning the URL of a password protected resource.