homepage Welcome to WebmasterWorld Guest from 54.197.189.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Determining the requested URL
runner




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

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.

 

simon2263




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

$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.

Simon

tombola




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

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

runner




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

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

rocknbil




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

#!/usr/bin/perl
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.

runner




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

Thanks for the code!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved