PDA

Click to See Complete Forum and Search --> : Passing parameters in CGI


zampag
Apr 27th, 2000, 04:02 AM
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]

Apr 27th, 2000, 08:26 AM
Plus symbols represent spaces.
Use:
...?rpt_name=My+Test+Report

Concorde
May 11th, 2000, 09:55 PM
Or you could use %20 instead of space :D

like:
?what%20ever

parksie
Jun 6th, 2000, 12:04 AM
Rather than using CGI.pm, it's often best to just shove this at the top of your script:


# 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)