CGI

What is CGI?

CGI stands for the Common Gateway Interface. It is a standard for external gateway programs to interface with information (in our case HTTP) servers.

That definition digests to the following:

Common

Well, common is just what you would expect. Something that is common is the same across several platforms (Netscape is c ommon on the Macintosh and Windows 95 Operating Systems). By making something common you make it easier for different OS's to do the same things. CGI is common amount Unix servers, Windows 95 servers and others. The hope is that when someone writes a CGI program that runs under Unix, it will only take a modest effort to make the exact same program run under Windows 95.

Gateway

A gateway is something that sits between two important points. The gateway to the university sits between the outside w orld (court street) and Ohio University (college green). In CGI the gateway sits "between" a program that is capable of input and output, and the HTTP server. For example, Netscape sends the web server some input from a form (defined in detail later) and the web server grabs that input and sends it to the a program, such as a white pages lookup script, the program then executes and returns the computed value to the server. The server then sends the results to Netscape.

This is how it works step by st ep for a white pages lookup program:

  1. Netscape presents the user with a form
  2. A user types in the name of the person she would like to look up and submits the information with a button
  3. Netscape sends the information to the web server
  4. The server sticks the information into an environment variable that the white pages program has access to
  5. The server then runs the white pages program
  6. The program examines what is in the environment variable and takes appropriate action, in this case fingers the white pages server
  7. The program then sends the output back to the web server
  8. The web server sends the output to the client

Interface

An interface is a specification. It is usually highly technical, and for our purposes is beyond the scope of this class. The interface for Windows 95 is the set of standards that define the shape and functionality of windows, shapes of scrollbars etc. etc. Follow this link for the complete specification for the CGI interface.

What can it be used for?

CGI can be used for just about anything you can think of. Basically, any idea you have about user interaction on the web can be implemented via a CGI program. If your department has a huge database of information that you would like people to access through the web, it can be done. You would have to have someone implement the database on the machine that is running a web server, and then write the gateway program that is capable of querying the database. It might take a while, and be a nontrivial program, but it can be done.

CGI can be used for more modest ventures as well. For example, many people like to have a record of who has visited their web site. So they implement a guestbook program that allows people to "sign in" and say hi. The guestbook program generates HTML files automatically based on user input.

Anything that requires user interaction can be implemented via CGI. What is nice about it is that the bulk of the User Interface (UI) has already been written. The UI is Netscape! You don't need to worry about mouse clicks and text boxes and buttons and all that nasty stuff associated with writing a graphical program, Netscape takes care of all that through some simple HTML (forms) and all you have to do is handle input and output. CGI is very nice in that respect.

What you need to utilize CGI

You need:
  1. A working knowledge of a programming language such as any of the following:
    C or C++
    Fortran
    Visual Basic

  2. A working knowledge of a scripting language such as any of the following:
    Perl
    Unix Shell (ksh/sh/tcsh)
    Applescript
    TCL

  3. An account on a machine that can run CGI programs, OR
  4. A machine that runs a web server that can run CGI programs

Ack! I don't know any of that stuff!

If you really want to write CGI programs for the web you are going to have to spend some time learning one of the above languages. This course will attempt to give you a good idea as to what that will entail. CGI is actually a pretty good way to learn one of these languages. I would suggest taking a trip to a good book store, (I recommend Borders) and look for a few introductory texts on the language you choose to write your CGI scripts in.

The examples given in this course include one very simple perl script and two small C programs.

[ Ne xt | Back | Topics ]

© 1995 Rich Barrette