separator

Take a quiz or make one of your own
Tutorial 5 - CGI Form Handling with Perl
What It's All About

In the previous tutorial we learned how to use cookies so that page views from the webmaster would not be tallied on the count file. We wrote a simple program that the webmaster could execute over the web to set a cookie. When a page view happened the count program looked for this cookie and if it found it the page view wasn't tallied.

This was a very simple example of a web transaction, i.e. the program to set the cookie, which interacts with the count program. In this article we will develop a more complicated type of interaction between two programs, using an HTML form to collect the data and put the results on server files. Then another program will read those files when needed and create its output according to what has been specified in them.

So the technique we'll be learning is how to handle forms from a web page. The application we'll be using this technique for is preparing responses to server errors.

Eh?

Here's what I'm talking about. Right now, open another browser window and go to a page on your site that doesn't exist. For instance, if your homepage is at http://www.mydomain.com/, type in http://www.mydomain.com/not-there/. You'll likely get a response like


HTTP/1.0
Error 404
Object Not Found

The requested page does not exist on this server.
Please check the spelling of the URL.
If you followed a link here, please use our
Guestbook to alert us to the problem.

There are different variations on this message, and your server may already permit you a way to customize this message. What we're going to apply our form handler to is changing this error message on the fly through a web transaction. In fact we're going to be able to customize the message for all 7 NCSA specified errors.

separator

© www.thecgibin.com