Creating Interactive Web Applications
The Common Gateway Interface (CGI) is an World-Wide-Web protocol for passing structured information between a Web client and another program, using the Internet as the transport and a Web server as an intermediary. Typically, data or query parameters are collected from a user by means of a "form" that is encoded in hypertext markup language (HTML) and rendered by the Web browser. Results are returned to the user by dynamic generation of HTML text and tags which are sent back to the Web browser for display.
The mechanisms of CGI are merely the standard input device, the standard output device, and environment variables. In this simplicity lies great power: CGI allows a Web browser to serve as the "front end" for virtually any type of application or database, residing anywhere on the network. The simplicity of CGI also, paradoxically, makes it the special domain of software virtuosos. The CGI developer must be fluent in HTML coding, Web server configuration, scripting, access rights, the commands and features of any database that is involved, and a host of other issues. As Shishir Gundavaram comments in the first chapter of CGI Programming on the World Wide Web:
One of the Internet's worst-kept secrets is that CGI is astoundingly simple. That is, it's trivial in design, and anyone with an iota of programming experience can write rudimentary scripts that work. It's only when your needs are more demanding that you have to master the more complex workings of the Web. In a way, CGI is easy the same way cooking is easy: anyone can toast a muffin or poach an egg. It's only when you want a Hollandaise sauce that things start to get complicated.
CGI Programming on the World Wide Web is evidently intended to be a companion volume to Musciano and Kennedy's HTML: The Definitive Guide (O'Reilly, 1996). The two books have similar designs and very little overlap in content. However, they will appeal to very different audiences. HTML: The Definitive Guide is a straightforward reference that any tyro can dip into for information as it is needed. CGI Programming, on the other hand, is a demanding tutorial and cookbook that must be assimilated in a sequential, methodical fashion.
Gundavaram spends the first few chapters on the underpinnings of CGI and shows how CGI can be used with a variety of languages, including Perl, C, C++, Tcl, the C shell (csh), and Visual Basic. He then presents a sequence of increasingly sophisticated CGI applications ranging from clocks and counters to games, tests, polls, and databases. Especially valuable are Gundavaram's demonstrations of the use of Ghostscript, gnuplot, and pgperl for the dynamic generation of Web charts and other graphics, and his discussions of "maintaining state" across a series of inherently stateless HTTP transactions.
CGI Programming is heavy going for the most part, and takes a great deal of UNIX-centric background information for granted -- ranging from regular expression parsing to the organization of "man" pages to spawning and forking of processes. Gundavaram's first love is clearly Perl, and the majority of the example applications are provided only in that language. A separate Perl tutorial and reference (such as O'Reilly's Programming Perl) will be indispensable while working your way through Gundavaram's book. Some code relies on the object-oriented features of Perl 5 and may appear unfamiliar even to Perl veterans.
A multitude of CGI books have appeared on the market over the last few months, even though CGI itself is becoming somewhat passe in the face of integrated Web server/database products, Java, and other new technologies. Gundavaram's CGI Programming on the World Wide Web stands above most other CGI books for two reasons: the depth and breadth of the author's experience in CGI programming, which is self-evident in the example applications, and the publisher's characteristically painstaking editing and production, which offsets the difficulty of the material and the author's occasionally fractured English.--Dr. Dobb's Electronic Review of Computer Books