Changing your htbin scripts to CGI scripts
If you have upgraded your server from NCSA httpd 1.0a5 to NCSA httpd
1.0, you have probably discovered that your old scripts don't work in
their ScriptAlias locations. This is because NCSA httpd 1.0 implements
the CGI specification.
CGI stands for the Common Gateway Interface. It is the next generation
of the script interface, called Common because many of the major HTTP
servers will be implementing it.
To use your scripts with CGI, you will have to change a few minor
semantic things to reflect the fact that CGI passes information in
different locations than htbin did.
Method
Whether your script is a GET script or a POST script, you
should check that your script is being accessed with the proper
method. This can be done with the environment variable
REQUEST_METHOD
. This variable will be either GET, HEAD,
or POST depending on which method was used to access your script.
The command line
For GET scripts, argv[1] used to be path information, and argv[2] used
to be the query string. This information can now be found in the
environment variables PATH_INFO
and
QUERY_STRING
respectively.
In addition, for non-form GET requests, the query string will be
decoded and placed on the command line. If you are writing a script to
handle forms, you will not get this information on the
command line.
For POST scripts, argv[1] used to contain the content length. This has
been moved into the environment variable CONTENT_LENGTH
.
DocumentRoot and ServerRoot
Because the environment variables DOCUMENT_ROOT
and
SERVER_ROOT
may have no equivalent in server packages
besides NCSA httpd, these have been removed from the CGI
specification. You should not have need of this data unless you are
looking for the unescape support program.
The Location: output header
If you used the Location: output header for scripts, you'll note that
URL specifications still work, but file paths are no longer absolute
filesystem paths. They are now virtual paths. This means the server
will perform Alias and DocumentRoot translation on this path before
retrieving the document.
There are many more features in the specification which you will want to take
advantage of. The amount of information now given to the script is
much greater than it was.
Rob McCool, robm@ncsa.uiuc.edu