Previous | Top | Next | Search | Comments

CGI programming


These sections provide information about CGI scripting, using Perl as an example.

One of the most powerful features of HTTP servers lies in their ability to run programs behind the scenes and return the results of these programs to the client. This is known as common gateway interface (CGI) scripting. Basic CGI scripts include the ability to display the current time or the number of users who have accessed a server. More advanced and useful CGI scripts allow readers to search databases, complete survey forms and have them sent to an email address, implement imagemaps, or take pictures of remote places and have the pictures returned.

CGI scripts are made available to a Web browser through the use of simple links, specialized URLs containing a question marks (?), ISINDEX HTML tags, or HTML+ FORMs. After the user submits an HTML document containing one of these elements, a query is passed to the HTTP server, which is passed on to the CGI script itself. The script processes the input, formats the output into HTTP codes and/or an HTML document, and returns these items back to the HTTP server. The server then passes it along to the client application.

CGI scripts can be written in almost any language. Common languages include C, Perl, AppleScript, VisualBasic, and Unix shell scripts. This section outlines how to write simple CGI scripts using Perl. Perl is freely distributed, runs on just about any computing platform, includes functions for doing TCP communications, and has complete string manipulation functions. Most importantly, Perl is has one of the best support groups available anywhere, the Internet.

Keep in mind that Perl may not be the best CGI scripting language for your particular need. It is always a good idea to use the best tool for your particular job and other scripting languages may provide more useful hooks to your server's operating system.


  1. Hello, World!
  2. Creating valid HTML
  3. Using environment variables
  4. Getting input from FORMS


  1. "Overview of CGI" - "This page contains pointers to information and resources on the Common Gateway Interface, a standard for the interface between external gateway programs and information servers." <URL:http://>

  2. "FastCGI" - FastCGI is a new, open extension to CGI that provides high performance for all Internet applications without any of the limitations of existing Web server APIs. <URL:http://>

  3. "Perl Language Home Page" - This is the offical home page for Perl <URL:http://>

  4. "[Perl Ports]" - This will take you to a randomly chosen FTP site hosting the Macintosh and Windows-based ported versions of Perl. <URL:http://>

  5. O'Reilly & Associates, Inc., "Software Library - Extras" - Here is a set of CGI resources specicically for WebSite. <URL:http://>

  6. Chuck Shotton, "Using FileMaker Pro with MacHTTP" - An archive with sample forms and CGI that shows how to hook MacHTTP to FMPro. <URL:http://>

  7. Chuck Shotton, "Writing Search Engines for MacHTTP " - This points to an archive containing C source code for a sample application that performs searches in conjunction with MacHTTP using the "srch" AppleEvent. <URL:http://>

  8. Danny Goodman, Complete AppleScript Handbook (Random House: New York, 1994)

  9. Dave Winer, "Frontier Community Center" - "Frontier is a scripting system for the Macintosh. Lots of features, lots of verbs. It used to be a commercial product, but now it's free. Why? Because I want Frontier to have a shot at becoming a standard. I think it'll be fun!" <URL:http://>

  10. Derrick Schneider, Tao of AppleScript (Hayden Books: Carmel, IN, 1993)

  11. Gisle Aas, "LIBWWW-PERL-5" - "The libwww-perl distribution is a collection of Perl modules which provides a simple and consistent programming interface (API) to the World-Wide Web. The main focus of the library is to provide classes and functions that allow you to write WWW clients, thus libwww-perl said to be a WWW client library. The library also contain modules that are of more general use." <URL:http://>

  12. John G. Cope, "Win-httpd CGI-DOS" - Here is a wrapper for Perl scripts written for DOS/Windows machines. <URL:http://>

  13. Lincoln D. Stein, "" - This is Perl 5 module for creating and processing HTML+ forms. <URL:http://>

  14. Lincoln D. Stein, "CGI::* Modules for Perl5" - Here is a collection of Perl libraries for creating Perl-based CGI scripts. <URL:http://>

  15. Matt Wright, "Matt's Script Archive" - A collection of Perl scripts as well as lists of other Perl script collections. <URL:http://>

  16. Matthias Neeracher, "MacPerl and PCGI" - This points to the FTP archive for MacPerl and PCGI, a script inserting the necessary resources into a MacPerl script so it can be executed as a CGI script. <URL:>

  17. Meng Weng Wong, "Index of Perl/HTML archives" - "This is a list of Perl scripts and archives involving HTML." <URL:http://>

  18. NCSA, "Common Gateway Interface" - This is the official specification for CGI scripting. <URL:http://>

  19. NCSA, "Mosaic for X version 2.0 Fill-Out Form Support" - This is the original specification for what was then called HTML+ FORMS. <URL:http://>

  20. Robert Godwin-Jones, "Guide to Web Forms and CGI Scripts for Language Learning" <URL:http://>

  21. Roy Fielding, "WWW Protocol Library for Perl" - "libwww-perl is a library of Perl packages/modules which provides a simple and consistent programming interface to the World Wide Web. This library is being developed as a collaborative effort to assist the further development of useful WWW clients and tools." <URL:http://>

  22. Sandra Silcot, "MacPerl Primer" - "This Primer is intended to assist new users get started with Macintosh Perl, and to point out salient differences for experienced Unix Perlers. This Primer is not a language reference manual, nor does it replace Matthias's documentation or Hal Wine's Frequently Asked Questions (FAQ) about MacPerl. The primer assumes you have already obtained and installed MacPerl, and that you have read the MacPerl FAQ." <URL:http://>

  23. Selena Sol, "Selena Sol's Public Domain CGI Script Archive and Resource List" - "n the following pages we have included both working examples of our scripts as well as the text of the code so that you can have one window open with the code and the other with the working script. Hopefully this design will help you figure out how we did what we did, so that you can take the ideas and run with them for your own needs." <URL:http://>

  24. Selena Sol, "Selena Sol's Public Domain CGI Script Archive and Resource Library" - This is a very useful collection of free Perl scripts and libraries for use on our HTTP server. <URL:http://>

  25. StarNINE, "Extending WebSTAR" - This is an extensive list of scripts and "plug-ins" for WebSTAR. <URL:http://>

  26. Steven E. Brenner, " Home Page" - Here is a long list of Perl instruction books as well as documentation for, a very popular Perl library for processing the input of HTML+ forms. <URL:http://>

  27. Yahoo!, "Gateways (Yahoo!)" - A collection on searching gateway scripts, as well as a number of CGI examples are found here. <URL:http://>

  28. Yahoo!, "CGI - Common Gateway Interface (Yahoo!)" - A large collection of CGI scripts. <URL:http:// CGI___Common_Gateway_Interface/>

Previous | Top | Next | Search | Comments

Version: 1.5
Last updated: 2004/12/23. See the release notes.
Author: Eric Lease Morgan (