8.3 Writing CGI Programs

8.3  Writing CGI Programs

  In the simplest mode of operation, a Web server simply returns a Web page corresponding to the URL requested by the browser. For example, when one types in http://pikespeak.uccs.edu on a Web browser, the request is sent by the browser to the server at pikespeak.uccs.edu. The server at

pikespeak.uccs.edu returns the default initial page for the site which, depending on the server, may be called index.html, index.htm or some other name based on the configuration of the Web server.

   However, quite frequently, a Web server needs to return a dynamic page, a page that is created by a program on the fly. A CGI program allows a Web server to contact other programs that can produce dynamic content. They can be simple programs producing simple dynamic content, or could be complex programs that query databases or map producing program and such. The term CGI stands for the Common Gateway Interface. It was originally developed by the National Center for Supercomputing Applications (NCSA) for use with the NCSA Web server. The CGI standard specifies how a server interacts with an application program that creates a dynamic document. CGI provides general guidelines. It does
not specify a particular programming language. Perl is a language that is very commonly used for implementing CGI programs. In addition, languages such as FORTRAN, C, C++, TCL, Unix shells, LISP, and AppleScript has been used by authors of CGI programs.      

The output of a CGI program is most frequently an HTML document. However, the output can, in general, be in any arbitrary document format. Many CGI programs generate documents in XML—the Extensible Markup Language. Since most CGI programs discussed in this chapter generate HTML code, a basic knowledge of HTML is assumed.