Developing Dynamic, Interactive Web Content Using CGI


Jeni Li Shoecraft

ASU West Information Technology
E-mail: jeni.li@asu.edu
URL: http://www.west.asu.edu/jenili

The Web is evolving - from plain text to rich content; from static publications to dynamic, data-linked documents; from serving a passive viewer with fixed-format information to processing user input and offering user-customized content.

CGI, or Common Gateway Interface, is one way to make Web pages dynamic and interactive. CGI is the non-proprietary protocol used by most Web servers to capture and communicate session information to and from server-side processes. In other words, it's the "glue" between the Web browser and your behind-the-scenes applications.

The purpose of this paper is to demonstrate when and how to use CGI (and its sister spec, WinCGI) on your Web site, from "hello world" to complex operations using server push and Netscape cookies - and to help you sidestep some common pitfalls in the process. It assumes you have some familiarity with programming concepts, and some degree of control over how your Web server is administered.

Many familiar applications on the Web - search engines, hit counters, guest books, feedback surveys - are CGI applications. More complex applications (such as ASU's "FASTT interactive", which accesses mainframe data through a SQL server) are also CGI applications. Many "canned" CGI applications exist, and you can write your own in virtually any programming or scripting language.

The key to CGI development is in understanding the environment the Web server creates. User input and session information are supplied to your application through environment variables and standard console input, usually in a special format that must be parsed. Your application, in turn, "speaks" to the browser through standard output, consisting of one or more HTTP headers and whatever information you choose to return.

Since CGI processes run on the server, they are browser-independent for the most part (although some special headers are not recognized by all browsers). They are also stateless; that is, each time a browser requests a given CGI application, the Web server creates a brand-new process with a brand-new environment and no recollection of any other process the server might have started or completed. The process begins with the request, and ends (generally speaking) with its output to the browser via the server.

The problem of "keeping state" among CGI applications is a hot topic among Web developers. This has been addressed in a variety of ways, including passing information in URLs and hidden form fields. Another method, specified by Netscape Corporation and known as "cookies", uses special HTTP headers recognized by most (but not all) browsers. As in any programming project, the "best" method to use depends on your application.

N.A. Web '96 Home Page

This page updated and maintained by:
Hope.Greenberg@uvm.edu Last update: 22 August 1996