CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Browser Info



May 17, 2001, 7:33 AM

Post #1 of 4 (946 views)
Browser Info Can't Post

I was wondering how can you take information that is stored into the browser url and get your cgi program to take it out. ( e.g. Thanks i really appreciate any information about or around this topic.


People Engrossed by a Reliable Language


May 17, 2001, 11:41 AM

Post #2 of 4 (942 views)
Re: Browser Info [In reply to] Can't Post

well do this..

(split things by the &)
($value1, $value2) = split(/\&/,$ENV{'QUERY_STRING'});

(Now split the name & values with the =)
($Url, $Url_value) = split(/\=/,$value1);
($Tires, $Tries_value) = split(/\=/,$value2);

$Url_value will eq
$Tires_value will eq 4

Heres an example:

if(($query =~ /Url=$url/) && ($query =~ /Tries=$tries)){
($value1, $value2) = split(/\&/,$ENV{'QUERY_STRING'});
($Url, $Url_value) = split(/\=/,$value1);
($Tires, $Tries_value) = split(/\=/,$value2);


sub test
print "Content-type: text/html\n\n";
$url = $_[0];
$tries = $_[1];

print "$url\n";
print "$tries\n";


Hope this helps ya...


May 17, 2001, 11:42 AM

Post #3 of 4 (942 views)
Re: Browser Info [In reply to] Can't Post

it is called "Parseing form data"

this is a popular one that alot of people use, it places each name into a form.. example:

$form{'board'} equals Forum2
$form{'Cat'} equals nothing

here is the function:

sub get_form_data {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
foreach $pair (@pairs)
@a = split(/=/,$pair);
$value =~ s/\+/ /g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/[\n\r]/ /sg; #remove \n
$value =~ s/\[\]//g; #remove []
push (@data,$name);
push (@data, $value);

hope this helps..

User / Moderator

May 17, 2001, 2:48 PM

Post #4 of 4 (937 views)
Re: Browser Info [In reply to] Can't Post

But of course that will not help for this example.

The script is called as a GET with the information in the URL behind a question mark


So the key/value pairs are hiding in $ENV{'QUERY_STRING'}, not in STDIN, which is where they would be in a POST. The earlier reply looked in the right place, but was hard coded for exactly two pairs rather than using the more standard @pairs.

And what if multiple checkboxes are picked like ?months=jan&months=feb that have the same name in the form? Only the last one will survive.

And an efficiency nit to pick. Why do you fill the @data array just to feed it to %form? You could replace the two push lines with

%form{$name} = $value;

Parsing CGI forms is harder than it looks. Which is what prompted Ovid to write use CGI or die; at Perlmonks, as metioned in an earlier thread.

Or if you don't want to use the full featured or CGI::Lite, CGI::Minimal, or the old perl 4, you could use my favorite, CGI::Thin.

Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives