As with most computer jargon, the term Common Gateway Interface can be fairly meaningless at first glance. So, before getting into what CGI can do, let's take a moment to define what CGI actually is.
- Common - CGI programs can be written with many languages. CGI can
be programmed in C, C++, Java, Perl, Visual Basic, or any other language
that can accept user input, process that input, and respond with output.
Further, CGI works with many different types of systems. CGI works on Mac, NT, Windows, OS2, Amiga, UNIX, and pretty much every operating system that runs web server software.
By the way, if you use a "platform independent" language like Perl or Java to write your CGI script, the exact same CGI script can be moved directly from one platform to another without it breaking! (4)
- Gateway - CGI's usefulness does not stem from what it can accomplish
by itself, but what it can accomplish by making partnerships with other resources.
I often see CGI as a middleman or a translator whose job it is to help more powerful resources like databases, graphics generation programs, or network applications talk to each other and work towards a common solution.
CGI is the gateway between the lone web surfer with her trusty web browser and the vast web of computers (each with their own specific language and protocols) and computer programs (each with their own interfaces and methods of output).
CGI translates between the language the client speaks (perhaps HTMLized English) and the multitude of languages spoken by the resources the client wants to utilize (such as SQL for relational databases). This is a crucial job, cause let me tell ya, my grandmother does not want to know how to speak SQL when she is browsing the web!
- Interface - CGI is not a language. Neither is it a program. CGI is a standard of communication, a process, an interface that provides well-defined rules for creating partnerships. The benefit is that if everyone follows the rules of the interface, then everyone can talk to each other. Thus, typically we say that we write "CGI programs" or "CGI scripts" that perform the functions of the common gateway interface.
Let's look at the CGI processes in the following chart.
Okay, so that is probably a lot of abstract stuff to take in all at once, especially if you have not worked with CGI already. So let's back up a minute and go over what CGI is by looking at it in the wild. Let's look at some examples of CGI in action.
- Processing Forms - One common use for CGI is providing a way for
web surfers to enter data into HTML forms and send that data to some site
administrator. With a feedback form, the web surfer can not only read pre-prepared
HTML documents, but can actually send feedback in response. Forget about
doing that with HTML alone. This form processing script actually takes the
data input by the web surfer and sends it as e-mail to the form administrator.
Another common form processing application is the guestbook that allows web surfers to leave publicly readable greetings. The CGI manages a common file on the web server that everyone can read and write to.
- Discussing Things - More than simply allowing clients to "talk back", CGI helps in creating an ongoing dialog between multiple clients. Bulletin Board System that actually lets many people collectively create an archive of related messages. And when you're done with that, check out how CGI implements Realtime Chat that allows people to chat anywhere in the world in real time (as if it were a telephone call but typed)
- Shopping - CGI has also been very useful in selling products on the web.
- Databases - Finally, CGI can be used to manage databases.
You can easily see that CGI makes for a much more profound surfing experience allowing web sites to offer useful and compelling services to surfers who may be interested in information or products offered. (5) However, there is a dark side!



