-
I am trying to pass a parameter on the URL string simliar to this :
h t t p://server.com/cgi-bin/load.cgi?rpt_name=My Test Report
The code for load.cgi looks like this :
#!/usr/local/bin/perl
require "sybperl.pl";
use CGI;
$query = new CGI;
$rpt_name = $query->param("rpt_name");
The $rpt_name variable only gets "My". If I put quotes around My Test Report, I get a server error. How can I get the entire string, even if there are spaces in the parameter?
Thanks
[Edited by zampag on 04-27-2000 at 05:03 PM]
-
Plus symbols represent spaces.
Use:
...?rpt_name=My+Test+Report
-
Or you could use %20 instead of space :D
like:
?what%20ever
-
Rather than using CGI.pm, it's often best to just shove this at the top of your script:
Code:
# read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # POST only
$buffer = $ENV{'QUERY_STRING'}; # GET only
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
This way, it's faster because it avoids the overhead of a function call and the object setup involved. It's also more portable to older perl systems (though there shouldn't be any)