Forum Moderators: coopster & phranque

Message Too Old, No Replies

Settings conditions based on the URL

Using CGI to read url and execute subs accordingly

         

Mr Anonymous

8:35 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



How do you read the URL box with cgi and set a condition where it executes a sub according to the url?

[example:

if ("the url" eq "stuff after '?' in url box") {
&subcalled;
}

]

Please help me out ^^.
thanks.

sugarkane

7:08 am on Aug 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld Mr_Anonymous

At it's simplest you can get the url using the CGI.pm module:

#!/usr/bin/perl
use CGI;
$query=CGI::new();
$url=$query->self_url;

You could then test $url using if () {} as in your example.

But I'm not sure - are you looking to call different subs based on the query string in the url (ie the part following the '?')?

claus

8:55 am on Aug 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript provides a method called "location.search()" - using this you will capture the stuff that is written after the questionmark in the url. I think you can just write like this:

var string = location.search()

In a cgi program you'll have to identify the part of the url that is located after the questionmark. Following sugarkanes example, you can do like this:

$url =~ \?.*$

This weird looking code isolates the part of the string "$url" that is located between the questionmark and the end of the line (the? is included.)

/claus



Welcome to WebmasterWorld Mr_Anonymous :)

Mr Anonymous

6:52 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



Thanks all, I appreciate the help and yes, sugarkane, after the "?" is what i was looking for. I knew how to in Javascript, I was just hoping to bypass it and only use CGI, but I guess come to think of it, Jscript would be a little less hectic ^^. Well, I appreciate the responses.

Anonymous

sugarkane

7:19 pm on Aug 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could also use

$foo=$ENV{'QUERY_STRING'};

Mr Anonymous

12:03 am on Aug 14, 2003 (gmt 0)

10+ Year Member



AGGHH! Thats great! I appreciate that so much sk. Thanks a bunch. :)