The Basics of CGI Developer's Guide - 6. Accepting Input From the Browser
In previous examples, you saw how to write a CGI program that sends information from the server to the browser. In reality, a CGI program that only outputs data does not have many applications (but it does have some; see Chapter 4 for examples). More important is the capability of CGI to receive information from the browser, the feature that gives the Web its interactive nature.
A CGI program receives two types of information from the browser.
* First, it gets various pieces of information about the browser (its type, what it can view, the remote host name, and so on), the server (its name and version, the port its running on, and so on), and the CGI program itself (the program name and where it's located). The server provides all of this information to the CGI program through environment variables.
* Second, the CGI program can get information entered by the user. This information, after first being encoded by the browser, is sent either through an environment variable (the GET method) or through the standard input (stdin—the POST method).
Environment Variables
Knowing what environment variables are available for the CGI program can be useful, both as a learning aid and as a debugging tool. Table 2.2 lists some of the available CGI environment variables. You can also write a CGI program that prints the environment variables and their values to the Web browser.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Table 2.2. Some important CGI environment variables.
Environment variable Purpose
|