4.4. Useful Scripts

When we fill in an order form and hit the Submit Query button, we simply get the heartening message:

Have a nice day

because the ACTION specified at the top of the form is to run the script mycgi.cgi and all it does is to echo that friendly phrase to the screen.

We can make mycgi.cgi more interesting by making it show us what is going on between Apache and the CGI script. Let's add the line env, which calls the Unix utility that prints out all the environment variables, or add the Win32 equivalent, set. Remember that you can't use echo to produce a blank line in Win32, so you have to produce a file, called new1 here, that contains just a RETURN and then type it:

   

#!/bin/sh
echo "content-type: text/plain"
echo
env

   

echo "content-type: text/plain"
type newl
echo
set

Now on the client side we see a screen full of data:

GATEWAY_INTERFACE=CGI/1.1 CONTENT_TYPE=application/x-www-form-urlencoded REMOTE_HOST=192.168.123.1 REMOTE_ADDR=192.168.123.1 QUERY_STRING= DOCUMENT_ROOT=/usr/www/site.cgi/htdocs HTTP_USER_AGENT=Mozilla/3.0b7 (Win95; I) HTTP_ACCEPT=image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* HTTP_ACCEPT_LANGUAGE= CONTENT_LENGTH=74 SCRIPT_FILENAME=/usr/www/cgi-bin/mycgi HTTP_HOST=www.butterthlies.com SERVER_SOFTWARE=Apache/1.3 HTTP_PRAGMA=no-cache ...

Get Apache: The Definitive Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.