Overview of the Common Gateway Interface

What is the Common Gateway Interface?

The Common Gateway Interface (CGI) is a standard for external gateway programs to interface with information servers, such as HTTP servers. The official specification for the Common Gateway Interface may be found at http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

CGI scripts or CGI applications?

Historically, many CGI applications were written in scripting languages such as Perl. Not surprisingly, CGI code called by the HTTP server was referred to as a CGI script. As the popularity of the web grew and the need for dynamic content increased, CGI applications written in languages other than Perl became more and more popular. These applications were referred to simply as scripts. Although the term script does not make intuitive sense for a compiled program, the term has stuck. In this manual, the terms script and application are used interchangeably.

CGI Processing

When an HTTP server receives a request for a CGI script, the server communicates to the script the details of the request. The HTTP server and a CGI script communicate in four major ways:

  1. Environment variables The HTTP server uses environment variables to pass information about the request to the CGI script. Depending on the type of request, the environment variables may or may not contain all the information required by the script to function properly.

  2. The command line The command line is only used for isindex queries. Generally, isindex queries should not be used; since the command line is used directly, they present many potential security risks.

  3. Standard input For HTTP POST or PUT queries, the HTTP server communicates information to the CGI script via standard input. The amount of information written to standard input is stored in the CONTENT_LENGTH environment variable.

  4. Standard output A script returns its output on standard output. The output can be a document generated by the script, or instructions to the server for retrieving the desired output.


GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Sat Jan 19 21:15:59 2008 for cgicc by doxygen 1.5.1