|
CGI
- Preamble
- What is CGI?
- Were can I get a CGI program that does xyz?
- How do I write my own CGI program?
- How do I use cookies?
- How do I solve this problem with my CGI program?
- How do I get my CGI program to talk to my database?
- Where can I get a list of all the available environment variables?
- What are Server Side Includes?
- What are some of the alternatives to CGI?
- For More Information
- Preamble
This FAQ should probably be read in conjunction with the FAQ for the HWG-Servers mailing list. Many CGI problems are in fact server problems, and vice versa. If there are questions that you were expecting to find here, such as the configuration of your web server to run CGI programs, for example, you will probably find those questions on that FAQ.
Table of Contents
- What is CGI?
CGI, the Common Gateway Interface, defines a standard for communication between HTTP servers and other programs, so that the content of a web page can come from a program, rather than from a static HTML page. CGI programs can be written in any language - CGI is not a programming language. CGI programs allow the web site to be interactive, rather than merely a digital pamphlet.
- Where can I find a CGI program that does xyz
There are a number of sites where you can get a large variety of CGI scripts for free that already do what you are trying to do. Unfortunately, in many cases, you get what you pay for. At the risk of endorsing any of these sources of CGI programs, and at the further risk of missing others that are more worthy, here are a few places that have a variety of prefab CGI programs:
Additionally, if you are just looking for modules that provide some of the functionality that you are looking for, you should probably take a look a the
Table of Contents
- How to I write my own CGI program
If you are interested in writing your own CGI program from scratch, there are a number of tools to help you do this. The language of choice in CGI programing is Perl, as it is very condusive to a rapid development cycle. If you are planning to use Perl, you can find a variety of Perl modules that will greatly reduce the effort in creating CGI programs. These can be found on CPAN (The Comprehensive Perl Archive Network). The most popular module for this purpose is CGI.pm, which gives you routines for doing everything from parsing forms and cookies to generating HTML. CGI_Lite.pm offers the minimal functionality you will need to deal with forms and cookies, and leaves out a lot of the other stuff that you may not need.
If you're planning to use another language, such as C or C++, you can also find libraries to do the grunt work of CGI programming for you.
- How do I use cookies?
Cookies are an extremely useful tool for storing state information. Cookies are stored on the client browser, and passed back to the web server that set them. You will find a very detailed cookie tutorial and FAQ at Cookie Central.
Table of Contents
- How do I solve my problem with this CGI program?
The important thing when you ask a question about a particular CGI
problem is to provide information. What server, what platform, what
language? Did you write the program, or
did you get it from somewhere else? What messages are appearing in
the browser window? What messages are appearing in the error log?
Don't just say "it didn't work" - what did you expect it to
do, and what did it actually do? If it was working before, and it is
not workin now, what did you change?
Questions contining the above information can generally be answered
very quickly.
Also, the following URL's are likely to solve any problem that
you will have with a CGI program:
The Idiot's Guide to Solving Perl/CGI Problems -
http://www.perl.com/perl/faq/cgi/idiots-guide.html
CGI specs at NCSA -
http://hoohoo.ncsa.uiuc.edu/cgi/
The CGI Resource Index -
http://www.cgi-resources.com/
Table of Contents
- How do I get my CGI program to talk to my database?
This question is addressed in some detail in the HWG-Servers mailing list FAQ.
Table of Contents
- Where can I get a list of the available environment variables?
The definitive list of environment variables is at http://hoohoo.ncsa.uiuc.edu/cgi/env.html.
You can get a listing of environment variables from your own server with the following two-line Perl program:
#!/usr/bin/perl
print "content-type: text/html\n\n" ,
map "$_ = $ENV{$_}<br>\n", keys %ENV;
Table of Contents
- What are Server Side Includes?
There is an excellent tutorial on SSI on the Apache web site at http://www.apacheweek.com/features/ssi.
Table of Contents
- What are some of the alternatives to CGI?
CGI is notoriously slow, because each time you request a CGI-generated document, the program has to load into memory, execute, and then pass you the document. A number of technologies have emerged in the last few years with a common idea - keep the process in memory at all times, so that we don't have to pay that start-up penalty every time. Some of these are
mod_perl, PHP, ASP (from Microsoft), and Cold Fusion (from Allaire).
Table of Contents
- For More Information
Table of Contents
|