An introduction to the InternetAdvanced HTML (4) [Archives:2003/667/Education]

archive
September 11 2003

What is CGI?
In previous chapters you have learned how to mark up content for your Web site using the HTML standard. Now, we will begin our exploration of the CGI (Common Gateway Interface), which will greatly enhance the level of interactivity on your site. With the use of CGI scripts, you can make your Web presentations more responsive to your users' needs by allowing them to have a more powerful means of interaction with your material.
What is the CGI anyway? Well, in order to answer that, you are going to need a little background information first.
Each time you sit down in your favorite chair and start surfing the WWW, you are a client from the Internet's point of view. Each time you click on a link to request a new Web document, you are sending a request to the document's server. The server then receives the request, gets the document, and sends it back to your browser for you to view.

The client/server relationship that is set up between your browser and a Web server works very well for serving up HTML and image files from the server's Web directories. Unfortunately, there is a large flaw with this simple system. The Web server is still not equipped to handle information from your favorite database program or from other applications that require more work than simply transmitting a static document.

One option the designers of the first Web server could have chosen was to build in an interface for each external application from which a client may want to get information. It is hard to imagine trying to program a server to interact with every known application and then trying to keep the server current on each new application as it is developed. Needless to say, it would be impossible. So they developed a better way.

These wizened developers anticipated this problem and solved it by designing the Common Gateway Interface or CGI. This gateway provides a common environment and a set of protocols for external applications to use while interfacing with the Web server. Thus, any application engineer (including yourself) can use the CGI to allow an application to interface with the server. This extends the range of functions the Web server has to include the features provided by a potentially limitless number of external applications.

How the CGI Works
Now that you have read a little background, you should have a basic idea of what the CGI is, and why it is needed. The next step in furthering your understanding of the CGI is to learn the basics of how it works. To help you achieve this goal, I will break down this material into the following sections:
The Process
Characteristics
The output Header and MIME Types
Environment Variables
The Process
The CGI is the common gateway or door that is used by the server to interface-or communicate-with applications other than the browser. Thus, CGI scripts act as a link between whatever application is needed and the server while the server is responsible for receiving information from, and sending data back to, the browser.

For example, when you enter a search request at your favorite search engine, a request is made by the browser to the server to execute a CGI script. At this time, the browser passes the information that was contained in the online form plus the current environment to the server. From here, the server passes the information to the script. This script provides an interface with the database archive and finds the information that you have requested. Once this information is retrieved, the script sends it to the server which feeds it back to your browser as a list of matches to your query.
Next week: More on advanced HTML.
——
[archive-e:667-v:13-y:2003-d:2003-09-11-p:education]