[Go Home] [Free Advice] [Free Software] [Back to those Frequently Asked Questions]


What is CGI?


CGI -Common Gateway Interface - is the first means by which Web Servers could be extended to do NEW or DYNAMIC behaviors above and beyond HTML file serving. New behaviors can be added to an EXISTING Web Server (or HyperText Transport Protocol Server - HTTP Server) without changing the software already written and running! The Web Server delegates the new behavior to a CGI Script.

All CGI Scripts interact with a Web Server the SAME WAY:

  1. Someone reading an HTML page with a Web Browser invokes a specific CGI Script at a specific Web Server through its Universal Resource Locator (or URL). The HTML page may contain a Form to gather some information from the reader.

  2. The Web Server at that location gets the Web Browser's request and relays user-defined inputs to the CGI Script.

  3. The GCI Script wakes up and reads any inputs provided to it by the Web Server.

  4. The CGI Script sees to it that the request is carried out. How does it do this? Easy - A CGI Script is a stand-alone program or application that runs when invoked by the Web Server.

  5. The CGI Script then returns a response or the results of the request back to the Web Server that asked for the behavior. These results may be in the form of a new HTML file, a graphics file, a text file - ANYTHING that a Web Browser can read and parse! The CGI Script can even write a CUSTOM HTML file - DYNAMIC HTML!

  6. The Web Server takes the results from the CGI Script and sends it back to the Web Browser.

  7. The Someone at the Web Browser now sees (or hears) the results!

The manner (or Protocol) in which the Web Server passes information to the CGI Script and the manner (or Protocol) in which the CGI Script returns the results to the Web Server are FIXED and totally described in a Common Gateway Interface Standard. Anyone who builds a commercial, shareware or freeware HTTP/Web Server supporting CGI follows this Common Gateway Interface Standard.


How do I use CGI?


If your Web Server supports CGI, you can write CGI scripts to do just about anything a Web Browser can handle. CGI Scripts can:

Here are two examples - take a look at these CGI Script actions:


What you should know about writing CGI Scripts

Your CGI Scripts run in the same operating environment as your Web Server. This is VERY IMPORTANT to remember!

1. You can write a CGI Script in ANY programming language that can be compiled for or interpreted by your Web Server's operating system.

All you need to do is follow the CGI protocol for communicating inputs and outputs from/to the Web Server! Your program must work with the ancient, yet venerated, C/UNIX concepts of the Standard-In and Standard-Out files for console-based applications. CGI Scripts can be written in:

2. Porting a favorite compiled CGI Script from one operating system to another is NOT necessarily easy.

CGI Scripts compiled for one operating system must be recompiled to be used on another operating system. But wait - this is really nothing new - this is the same as Windows and Macintosh versions of the same applications which we all work with today!

3. Porting a favorite interpreted CGI Script from one operating system to another is easy!

CGI Scripts written in Java and PERL can be easily moved from UNIX to Windows to Apple Macintosh to OS/2 - as long as the interpreting engine for those operating systems is already there! Interpreted applications run in a "simulated" computer or "virtual machine" - an interpreter. The simulated machine runs the program. The code underneath the simulated machine gets ported from one operating system to another. It's nice to let someone else handle this effort for us!


Last Revised: April 25, 2000
Copyright © 1996 - 2000 HomeWorlds (TM) All Rights Reserved.
HomeWorlds WebMaster