The Library of Web Design - CGI
Home | Graphical Version
The web is filled with CGI forms - surveys, search engines, even ordering forms, but how does one create one. That is the subject of this informative pamphlet.
- What is CGI?
- Creating CGI Programs
- Bibliography and Suggested Reading
What is CGI?
Common Gateway Interface(CGI) allows web pages to communicate with computer programs through forms. A perfect example would be a search engine, like the one created to search this very web site. Please take a look at the Search Engine. I hope you enjoyed it.
The first thing you must have is a form. Edmond wrote a handy guide to placing form elements, in chapter 12 of his book, named "Forms." Next, we must examine the technical aspect. The form tag takes a "method" parameter. This may be either "get" or "post." The "get" method hands the parameters to the program in one long string attached to the URL. The "post" method gives the data directly to the program. Our search engine uses the "get" method. When you do a search, you can see the data you entered in the navigation bar. Once you have finished you form, it needs a "submit" input. This takes the form of a button. When the button is clicked, the data entered is sent to the program listed in the "action" parameter of the form tag. You may also use an input of the type "image" which will act as a submit button, but will add an "x" and "y" field to the data sent to program. These fields tell the program where the image was clicked.
Creating CGI Programs
You can create CGI programs in most programming languages, but the program must be in a language supported by your server. For example, if you write an amazing CGI program in C++ on your Windows 95 computer, don't try and upload it to a UNIX server. It must be compiled for UNIX. Languages that can be used have variables to access the information provided by the form and a method to send data back to the client. You should consult the documentation to find out.
PERL is a very popular language because of its portability. You can write the program on a Windows 95 machine and upload it to a UNIX server. Writing a PERL program for a UNIX server (most web-servers are UNIX, including the one hosting this page) is easy. You just write the program, and upload the file to the cgi-bin directory. You need not compile it. You upload your form, and your ready to go becuase PERL is built into UNIX. As a matter of fact, the only hard part is writing the PERL script. Of course, this is not a guide to (the rather large) PERL language, but you can learn about it at the PERL hompage (www.perl.com). It has many similarites to C++ and Java (namely flow control, i.e. if statements, for statements, etc...) so it should not be too foreign for veterans of such languages.
Another in the long list of acronyms in this pamphlet, Active-Server Pages allow easy server-side programming in VBScript. There is only one catch; ASP is only available on Windows NT. However, ASP is even easier then writing a PERL CGI script in UNIX. You write a normal HTML file (with an extension of ".asp"), and insert VBScript into it. The server processes these scripts (the browser used does not mattter because ASP is server-side). You can find out more about ASP from the very company that created it at the Site Builder Network (www.microsoft.com/sitebuilder).
Bibliography and Suggested Reading
The Sitebuilder Network
Marshal, James. "CGI Made Really Easy." 1998 <www.jmarshall.com/easy/cgi> (Aug. 98)
Home | Back to top