Copyright (C) 1999 by Steve Litt. All rights reserved. Materials from guest authors copyrighted by them and licensed for perpetual use to Troubleshooting Professional Magazine. All rights reserved to the copyright holder, except for items specifically marked otherwise (certain free software source code, GNU/GPL, etc.). All material herein provided "As-Is". User assumes all risk and responsibility for any outcome.
The CGI program sends info to to the browser simply by outputting that info to stdout (the same device that normally writes to the computer monitor).
The CGI program receives info from the browser in one of two ways, called GET and POST. In the GET method, the browser's information is available to the CGI program through the QUERY_STRING environment variable. In the POST method, the browser's information is available to the CGI program through the CGI program's stdin, with the CONTENT_LENGTH environment variable containing the number of bytes transmitted to the server's stdin. Note that the CGI program can deduce whether the communication is GET or POST by reading the REQUEST_METHOD environment variable. Since POST is by far the more common, the remainder of this Troubleshooting Professional will concentrate on the POST method.
That's it. That's CGI. Did you notice nothing in the above description restricted CGI to a specific computer language (like Perl)? While Perl is one of the most productive CGI languages, CGI can be written in any language capable of reading environment vars and stdin and writing stdout. Perl, Python, C, C++ and shellscript are commonly used, although obviously Perl is the most common.
In a later article, this issue of Troubleshooting Professional offers a series of CGI scripts, written in shellscript and Perl, that can be used as testpoint access tools.