CGI scripts on www.washington.edu
Before you begin to write a script, you should check if there is already a script available for you to use, such as mailto. However, there may be times when you need to write your own script.
If you are writing your own script using Perl, you should use as many already-provided packages and libraries as possible. For most scripts, CGI.pm is very useful. In addition, you should make sure that you have use strict;
in your code; this package finds many errors before they happen.
A Perl CGI example is available to help you get startedI. If you are having problems with your CGI, you will want to read through the Debugging Case Study.
Differences from Other Web Environments
The info cluster, because of its distributed nature, has some restrictions for the CGI author:
- There is no developer-accessible
/cgi-bin/
directory; all your scripts need to be in your document directories with the .cgi
extension.
- Your script must not write any files into the web directories. Because of the need to access files in the developement directories, your scripts actually will be able to write there. But once your scripts are in production, they will not have the ability to change files:
- Because files are distributed from a central location, any file which differs from that master copy will get overwritten with the master version, so all changes made by a script would be lost.
- There is more than one production web server, each with its own copy of the files. Any changes made on one system would not be reflected on the other systems.
- Not allowing scripts to change data files increases security; if there were a problem with a CGI, it could not gain access to files which should not be changed.
- If you need to use a temporary directory, use the environment variable
SERVER_TMPDIR
for the path. Note that this directory is specific only to that individual web server, and not shared between the multiple servers.