The cgi-lib.pl Home Page
Intro /
Documentation /
Examples /
Books
cgi-lib.pl
The cgi-lib.pl library was the de facto
standard library for creating
Common Gateway Interface (CGI)
scripts in the Perl language.
Welcome to the official Web site for cgi-lib.pl.
The cgi-lib.pl library makes CGI scripting in Perl easy enough for
anyone to process forms and create dynamic Web content.
The library has the following features:
- Extremely simple to learn and easy to use
- Designed for operation under Perl5 and Perl4
- Very efficient
- Compatibility with all CGI interactions, including File Upload
- Convenient utility functions
- Compatible with Perl5 security features such as taint, warnings,
(command line options -Tw) and use strict;
- Debugging facilities
- Good starting point for migration to more sophisticated libraries
Current versions of cgi-lib available:
- Version 2.18 is the latest released
version of cgi-lib.pl. New features in version 2 include support
for file upload, improved robustness, and aids for debugging.
As of version 2.15, there are work-arounds for
bugs in Microsoft Internet Explorer File Upload. 2.18 avoids
spurious Perl warnings.
- Version 1.14 is simpler to understand
than the 2.x series. If you want to get an idea of how cgi-lib works,
you'll probably want to look at this code.
- There is a modified version by Scott Stricker
that works better with ActivePerl.
Note: In order to prevent servers from actually executing the
library, a .txt suffix has been added to the filename for cgi-lib.pl.
After downloading the files, you will need to remove the .txt suffix
before using the library. That is, after download, you should
ensure that the the name of the file on your system is cgi-lib.pl.
Documentation
The official documentation for cgi-lib.pl applies
only to version 2 of the library. However, a number of tutorials that
describe how to use cgi-lib.pl in your own scripts
can be found online on the WWW.
Tutorial Examples
Perl4 and Perl5
It is extremely easy to use cgi-lib.pl, and most people can pick
it up from just a few examples. The following scripts work equally
well under Perl4 and Perl5
- Simple form:
A plain HTML file (do 'view source' after loading it to see the HTML)
which produces a form with a variety of input elements and the
source code to a script which processes
its results.
- Comboform:
It is often convenient to conflate the form and the script. This can
be done by having one script file which acts
differently depending upon whether it is given parameters or not.
(Sophisticated scripts may actually output new forms on the basis
of previous forms.) The source code
to this example creates a comboform which unifies the form and script
from the previous example.
- File upload:
This is a simple form and script demonstrating how to use cgi-lib.pl to
receive a file upload. The script's
source doesn't need to do anything special to deal with uploaded
files because everything is handled by cgi-lib.pl.
The Perl5 version (below) shows how to spool the files to disk while
using very little RAM -- useful for very large uploads.
- Minimalist comboform:
A minimalist form and script
of whose source contains only 6 lines.
Note that the script doesn't really produce entirely valid HTML,
but it will work on virtually every browser.
Perl5
The above examples are also available in a form which uses Perl5
idiom. (The scripts above run on both Perl4 and Perl5, whilst those
below only run on Perl5.) Note that all of these scripts incorporate
-Tw and use strict which turns on taint
checks for security as well as warnings and strict to
help you avoid making stupid mistakes.
Books discussing cgi-lib.pl
The cgi-lib.pl library is described in a large number of
widely available books. Following is a list of some which have Web
pages.
Credits
cgi-lib.pl was written by Steven E. Brenner.
Thanks are due to many people for reporting bugs and suggestions
especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen, Andrew
Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews, Tom
Christiansen, Andre Pool, Matthew Baird, Roman Pozlevich, Ryutaroh
Matsumoto, Roger D. Linder. Edwin Aoki
has provided much help with documentation, examples, and support for
cgi-lib.pl.
Intro /
Documentation /
Examples /
Books
Copyright © 1998
Steven E. Brenner / cgi-lib@pobox.com
$Date: 1998/02/20 05:08:40 $