4. Example programs

[ Next | Up to Table of Contents | Previous ]

4.1. query-results

This is a generic forms parser which is useful for testing purposes. It will parse both GET and POST forms successfully. Simply call it as the form "action", and it will return all of the names and associated values entered by the user.

4.2. mail.cgi

This is a generic comments program which will parse the form, check to see if the intended recipient is a valid recipient, and send the e-mail if so.

You will want to edit two things in the source file: WEBADMIN and AUTH. WEBADMIN is the complete e-mail address to which the comments should be sent by default. AUTH is the exact location of the authorization file.

The authorization file is simple a text file with a list of valid e-mail recipients. Users will only be able to use this program to send e-mail to those listed in the authorization file. Your file might look like this:

In the above case, you would only be able to send e-mail to web@www.company.com and jschmoe@www.company.com. Make sure you include the value of WEBADMIN in your authorization file.

The following are valid variables in your form:

If there is no to variable defined in the form, the mail will be sent to WEBADMIN by default. mail.cgi will reject empty forms.

mail.cgi adds a "Sent-By:" header on each message so recipients know that the message was sent by this program and not by a regular mail client.

4.3. index-sample.cgi

Imagemaps have become increasingly popular to use on home pages. Unfortunately, imagemaps are not lynx friendly; if you forget to include some sort of text index as well, lynx users will not be able to access any of your subpages.

You can circumvent this problem by using a CGI program as your home page rather than an HTML page (or by using server-side includes). This CGI program will determine whether your browser is a graphics or text-browser. If it is a text-browser, it will send a text HTML file, otherwise it will send a graphics HTML file.

You will need to create two HTML files: a graphical and a text one. Place the names of these files in the macros: TEXT_PAGE and IMAGE_PAGE.

4.4. nph-ignore.cgi

A simple example of a no parse header program. If you use imagemaps, you can set "default" to /cgi-bin/nph-ignore.cgi. Whenever someone clicks on a part of the picture which is undefined, the server will just ignore the request.

Next | Up to Table of Contents | Previous ]
Last modified: Sun Aug 13 17:14:04 1995