|
CGI: What the Heck Is That?
|
By Richard Lowe
[Hits: 3223]
|
|
Let's unlock a little bit of the mystery about something calledCGI. If it helps any, CGI means Common Gateway Interface. Thisis a method which is used to exchange data between the server(the hardware and software that actually allows you to get toyour web site) and a web client (your browser). CGI is actuallya set of standards where a program or script (a series ofcommands) can send data back to the web server where it can beprocessed.
Typically, you use standard HTML tags to get data from a person,then pass that data to a CGI routine. The CGI routine thenperforms some action with the data.
Some of the more common uses of CGI include:
- Guestbooks - The CGI routine is responsible for accepting thedata, ensuring it is valid, sending an email acknowledgementback to the writer, perhaps sending an email to the webmaster,and creating the guestbook entry itself.
- Email Forms - A simple CGI forms routine just formats the datainto an email and sends it back to the webmaster. Morecomplicated routines can maintain a database, send anacknowledgement and validate data.
- Mailing List Maintenance - These routines allow visitors tosubscribe and unsubscribe from a mailing list. In this case, theCGI routine maintains a database of email addresses, and thebetter ones send acknowledgements back to the visitor andwebmaster.
A CGI routine can be anything which understands the CGIstandard. A popular CGI language is called PERL, which is simpleto understand and use (well, compared to other languages). PERLis a scripting language, which means each time a PERL routine isexecuted the web server must examine the PERL commands todetermine what to do. In contrast, a compiled language such asC++ or Visual Basic can be directly executed, which is fasterand more efficient.
Okay, in a nutshell (and greatly simplified), here's how itworks:
1) You (the webmaster) specify a form tag which includes thename of the CGI routine.
2) You create HTML tags which retrieves data from your visitors.
3) Each of the input tags includes a variable name. The datawhich is retrieved from the visitor (or directly set if the tagincludes the "hidden" qualifier) is placed in the variable name.
4) When the visitor presses the "submit" button, the CGI routinewhich was specified in the form tag is executed. At this time,the CGI routine "takes control", meaning the browser essentiallyis waiting for it to complete.
5) This CGI routine can get data from variable names. Itretrieves the data and does whatever action is required.
6) When the CGI routine finishes, it returns control back to theweb client (the browser).
Some important things to remember about CGI routines:
- You can install CGI routines on your own site if your hostallows it - Addr.Com is an example of a web host which allowsfor CGI routines. Some web hosts do not allow you to installyour own routines but do provide some pre-written ones to you.If these are not sufficient for your needs, you can find aremote hosting service to provide the necessary functions.
- Generally, if you install your own routines they must beinstalled in the cgi-bin directory of your site. This is aspecial location which allows scripts and programs to beexecuted.
- CGI routines work best on Apache-style servers. Windows NT andWindows 2000 does support CGI, but it tends to be slow andproblematic.
- If you use a remote hosting service, you must remember thatalthough they appear to be giving you this for free, you areactually paying a price. Usually they want to displayadvertisements, although some of them actually take visitorsaway from your site.
- When you write a CGI routine, you have the choice of ascripting language like PERL or a compiled language such as C++or Visual Basic. Anything which can execute on the web server isacceptable.
I hope this short introduction to CGI has cleared up some of themystery.
|
|
|
|
|
|