Chapter 35. How CGI Scripting Works

If you browse the Web for very long, you are sure to come across the term CGI, or Common Gateway Interface. CGI refers to the communications protocol by which a web server can communicate with other applications. For example, a CGI application, sometimes called a script, is often used to enable Web users to access databases or to get information from forms people fill out. CGI can also be used to create agents that do things such as check a website to see whether it has any broken links. (By the way, don't confuse CGI as used on the Internet with the term Computer Graphics Imaging, also called CGI. Computer Graphics Imaging is a technology used to create special effects in movies.)

Essentially, CGI is a standard way in which the Web interacts with outside resources. Often, that outside resource is a database. You've probably run CGI scripts many times without knowing it. For example, if you've filled out a form on a web page to register to use a site and then later received an email notification with a password for you to use, you've probably run a CGI script. In that case, the CGI script probably took the information you filled in on the form and performed several actions on it, including putting the information in a database, automatically creating a password, and then sending you mail.

CGI and CGI applications are often confused. CGI applications receive data from the server and return the data via the Common Gateway Interface. CGI applications are written in a variety of programming languages, including Perl, PHP, and ASP, although they can be written in C, C++, Pascal, AppleScript, or others as well. CGI itself is a standardized means of communicating between a CGI application and the HTTP server. It's the "doorway" of sorts through which the web server sends requests and the CGI application collects and returns data.

In the example of providing information on a web page designed to accept user input, CGI performs many tasks. First, you submit unique informationsuch as a name or email addressto the server for processing. Next, the server redirects the information to a CGI application that is called by the form "submit." CGI scripts are activated by the server in response to an HTTP request from the client. Lastly, a CGI application might send form data to another computer program, such as a database; save it to a file; or even generate a unique HTML document in response to the user's request. This is known as an interactive form.

In the illustration that accompanies this chapter, we'll look at a CGI program that enables someone to search a movie database for information.

How the Internet Works
How the Internet Works (8th Edition)
ISBN: 0789736268
EAN: 2147483647
Year: 2004
Pages: 223 © 2008-2017.
If you may any questions please contact us: