|
An Introduction to CGI scriptingThe Common Gateway Interface(CGI) is a specification for how programs are to be written to enable a web client to ask a web server to run the program on the client's behalf. It is not a scripting language by any stretch but rather a few simple rules to which programs should adhere when being written for the web. A CGI query works as follows:
+-------------------+ +-------------------------------+
| Client Machine | | |
| +--------------+ | | +-------------+ |
| | BROWSER |-|--request---->| | httpd | Web Server |
| +--------------+ | | +-------------+ Machine |
| |<--response---| \/ /\ |
+-------------------+ | +-------------+ |
| | cgi app. | |
| +-------------+ |
+-------------------------------+
The client machine asks the web server for a page that happens to involve a CGI request. The web server program on the web server machine(httpd) will then run the cgi application and send the results back to the client machine. This differs from a regular web page request in that the server actually has to run a program to generate the output instead of simply opening a file. CGI programs can also be used to generate any type of information on the fly. For example, the counter on the UofL homepage is actually an image file generated dynamically every time the page is requested. The browser doesn't know that it's getting a program, it only knows it's getting an image of some sort. The FormMost CGI programs rely on an HTML form to get the information to them. An example would be the UofL mail gateway. This program takes information from a form and processes that information to generate output for the user. There are a few other ways that CGI programs can get their information.
The form; however, remains the most effective. A few examples of forms used on UofL's site are: Forms are quite varied in what they do and how they accomplish it. The thing to remember is that it is not the form but the program at the other end that does the work. The example forms are simply html that sends information to a program. They do not run anything. The programs that are called are where CGI comes in. How CGI information is gathered by the program.All CGI information that comes into a program must be parsed or processed somehow. The documentation for CGI and how the information comes into the computer is stored at NCSA. How the program handles this information is dependent upon the language in which the program is written. The examples given on athena will be for UNIX and written in shell or PERL. There are libraries all over the 'Net for most languages to help with the basic cgi stuff. The basic items to remember are:
Examples of CGI in action on UofL's siteThere are hordes of CGI programs on UofL's site. These are just a few examples that can be used by anyone. Documentation for the supported and documented programs that have been developed or modified for UofL is at http://www.louisville.edu/docs/. That page can be an invaluable source for how-to and FAQ pages concerning programs on the web server.
Common questions about CGI programmingIt is important to have a working program in order to have a working CGI script. Below is a list of common issues and their resolutions.
|