PerlHoo, Part II | 4 | WebReference

PerlHoo, Part II | 4

PerlHoo, Part II

Building the URL

In page 3 of PerlHoo, Part I, we discussed how PerlHoo interacts with URLs to display directory categories. The category is stored in the PATH_INFO environment variable when we append it to the URL of our PerlHoo script.

Example:
http://www.webreference.com/cgi-bin/perl/3/perlhoo.pl/Computers/Perl

The URL to the script would be:
http://www.webreference.com/cgi-bin/perl/3/perlhoo.pl

The PATH_INFO environment variable would contain:
Computers/Perl

The easiest way to tell the perlhoo.pl script we wanted to recommend a new site would be to simply add some information to the QUERY_STRING environment variable. In the URL, we will do it by appending ?add to the URL like so:
http://www.webreference.com/cgi-bin/perl/3/perlhoo.pl?add
Then we can add code to perlhoo.pl to catch the request that's passed in through the URL query string.

A better way to visualize this concept is to print all the CGI environment variables to the browser with our handy printenv.pl script:
http://www.webreference.com/cgi-bin/perl/printenv.pl/Computers/Perl?add

You should see some similar to the following:


SERVER_SOFTWARE = Apache/1.3.3 (Unix) mod_perl/1.16
GATEWAY_INTERFACE = CGI/1.1
DOCUMENT_ROOT = /www
REMOTE_ADDR = 127.0.0.1
SERVER_PROTOCOL = HTTP/1.0
SERVER_SIGNATURE = 
Apache/1.3.3 Server at eisen.metashare.com Port 80
REQUEST_METHOD = GET
QUERY_STRING = 
HTTP_USER_AGENT = Mozilla/4.5 [en] (X11; U; Linux 2.2.2 i586)
PATH = /opt/kde/bin:./:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/sbin:/sbin:/home/eisen/bin:/usr/sbin:/sbin
TZ = GMT
HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
HTTP_CONNECTION = Keep-Alive
REMOTE_PORT = 1052
HTTP_ACCEPT_LANGUAGE = en
SCRIPT_NAME = /cgi-bin/printenv.pl
HTTP_ACCEPT_ENCODING = gzip
SCRIPT_FILENAME = /usr/local/apache/share/cgi-bin/printenv.pl
SERVER_NAME = eisen.metashare.com
REQUEST_URI = /cgi-bin/printenv.pl
HTTP_ACCEPT_CHARSET = iso-8859-1,*,utf-8
SERVER_PORT = 80
HTTP_HOST = eisen
SERVER_ADMIN = eisen@eisen.metashare.com

http://www.internet.com

Produced by Jonathan Eisenzopf and
Created: April 20, 1999
Revised: April 21, 1999

URL: http://www.webreference.com/perl/tutorial/3/