The Common Gateway Interface (CGI) is a standard protocol for enabling applications (commonly called CGI programs or CGI scripts) to interact with Web servers and (indirectly) with clients (e.g., Web browsers). CGI is often used to generate dynamic Web content using client input, databases and other information services. A Web page is dynamic if its content is generated programmatically when the page is requested, unlike static Web content, which is not generated programmatically when the page is requested (i.e., the page already exists before the request is made). For example, we can use a static Web page to ask a user to input a ZIP code, then redirect the user to a CGI script that generates a dynamic Web page customized for people in that geographical area. In this chapter, we introduce the basics of CGI and use C++ to write our first CGI scripts.
The Common Gateway Interface is "common" in the sense that it is not specific to any particular operating system (such as Linux or Windows) or to any one programming language. CGI was designed to be used with virtually any programming language, such as C, C++, Perl, Python or Visual Basic.
CGI was developed in 1993 by NCSA (National Center for Supercomputing Applicationswww.ncsa.uiuc.edu) for use with its popular HTTPd Web server. Unlike Web protocols and languages that have formal specifications, the initial concise description of CGI written by NCSA proved simple enough that CGI was adopted as an unofficial standard worldwide. CGI support was incorporated quickly into other Web servers, including Apache.