Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Determining the requested URL



7:58 am on Jan 21, 2006 (gmt 0)

10+ Year Member

My web page relies heavily on SSI includes to minimize mailtenance. One of my SSI includes calls a script that generates the html code for a row of notebook tabs. It's basically a menu system that runs across the top of the web page.

My script needs to know what URL the browser requested so it can make one of the notebook tabs darker.

For instance, if a user clicks on the notebook tab labeled HOME, the home page will be displayed and the SSI include that created the notebook tabs made the HOME tab a darker color. The cgi script needs to know what URL was requested so it can determine which tab to make a darker color.

In my script I tried getting $ENV{QUERY_STRING} but it didn't work. After looking into this a little more it appears that $ENV{QUERY_STRING} is only available when processing input from a form. My app is not a form so I need to figure out a way for this script to determine which URL the browser requested.

My O'Reilly book on CGI programming isn't very clear on this.


8:22 am on Jan 21, 2006 (gmt 0)

10+ Year Member

$ENV{'QUERY_STRING'} holds anything sent in the URL after the '?' character - typically this is data sent from a form using the GET request method, but could also be an anchor href with query string data hard-coded into it, for example

<a href="http://www.some.com/cgi-bin/some.cgi?home">A link</a>

In this case, some.cgi would see "home" as the value of $ENV{'QUERY_STRING'}. I guess you could use this as the basis for your scripts, so long as you coded all your links in this fashion.



10:45 am on Jan 21, 2006 (gmt 0)

10+ Year Member

If you have URLs like this one: http://www.example.com/info.html, you can use $ENV{'REQUEST_URI'} instead of $ENV{'QUERY_STRING'}


3:47 pm on Jan 21, 2006 (gmt 0)

10+ Year Member

REQUEST_URI works like a champ! This env variable is not even listed in my O'Reilly CGI programming reference book. That's weird.


8:32 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

print "content-type: text/html\n\n";
foreach $k (keys %ENV) { print "key: $k value: $ENV{$k}<br>\n"; }

Throw that in a file and you will get all of the environment variables served up by your host, as they indeed differ from machine to machine and even domain to domain. But PLEASE delete it after you're done with it as it can be used nefariously if found.


12:00 am on Jan 23, 2006 (gmt 0)

10+ Year Member

Thanks for the code!

Featured Threads

Hot Threads This Week

Hot Threads This Month