CGI Scripts
CGI Caveats |
Language Choice |
CGI and Forms
When you attempt to view a Web page with your browser,
the browser sends a request to the machine that holds the
file for the page you are requesting. If that machine finds
the file (and there are no problems such as your being restricted
from accessing the file), the machine sends, or "serves",
a copy of the file to your browser. For this reason the
software that provides a copy of the file to you is called
a "server". (The browser, which requests the file from the
server, is an example of a "client program"; there are many
other types of client programs besides browsers.)
CGI Scripts Produce
Dynamic Documents
CGI scripts are programs that allow you to have a server
do things other than "just" present graphics, text, and
sound. CGI stands for Common Gateway Interface,
and CGI scripts are also sometimes referred to as "gateway
scripts". (Technically, CGI is the means by which programs
access servers on Unix platforms. Other platforms use other
methods for this sort of interaction, but the term "CGI"
is frequently used on these systems too.)
If you link such a program to a Web page, you can execute
the program by simply clicking on the link, just as you
can go to another page or display an external image by clicking
on a link to it. For example, click here
to display the current date and time. Since the time is
changing continuously, it is clear that clicking on this
link did more than just access a static file on a server;
something on the server looked up the date and time and
sent it back to us. In this case, that something was a very
simple CGI script.
The Power and Limitation
of CGI Scripts
The preceding example provides a small hint at what can
be done with gateway scripts. They can also accept user
input and perform different actions based on that input.
They can be used to access databases from within Web pages
(in fact, although we didn't mention it at the time, we
used gateway scripts to obtain information from databases
when we examined tools
for finding things on the Web.) And they can also add
animation to Web pages.
So there are a number of ways such programs can transform
a page from just a document to be read into a dynamic display
or a useful tool. We'll look at some specific examples of
CGI programs in action, and we'll show you one that you
can use to perform simple processing of user input. But
before you become too excited by the possibilities, we have
to admit, unfortunately, that there are reasons why instruction
in the creation of such programs is beyond the scope
of this Tutorial.
|