Writing CGI Programs

Enough of the background, now it is time to see some actual CGI Programs. We'll start with the simplest program, the classic "Hello World", done in CGI. Then we will add elements demonstrating other aspects of CGI.

In order to run a CGI program, your web server must be configured to run CGI (enabled by default in Apache) and the server must recognize the program as a CGI program rather than a static file. In Apache, this is controlled via the access.conf and srm.conf files. Web servers will generally recognize CGI programs two ways, either by the directory they are in (generally cgi-bin), or or by the suffix on the script. (generally .cgi or .pl for perl). The file must also be readable and executable by the user id that the web server is running as. (Generally "httpd" or "nobody")

Hello World Hello World is a good example of the most basic CGI program. Here is the static HTML for Hello World, and the CGI code needed to produce it.
CGI Environment Variables Every CGI program has certain default environment variables available to it These variables lead to handling user input.
Error Output As soon as a program gets more complex than Hello World, it seems like you need to look at error handling.
URLs, HTTP, and Encoding. Before we get to user input, we need to review some background.
Getting User Input Get, Post, and processing form data
More Forms More Complex Forms Examples
Checking a password Using the "crypt" function to verify a Unix style password.

Next Previous Overview

Copyright 2001 - Andy Welter