Results 1 to 4 of 4

Thread: Passing parameters in CGI

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    13

    Unhappy

    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]

  2. #2
    Guest
    Plus symbols represent spaces.
    Use:
    ...?rpt_name=My+Test+Report

  3. #3
    New Member
    Join Date
    May 2000
    Location
    Årdal, Norway
    Posts
    5
    Or you could use %20 instead of space

    like:
    ?what%20ever

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width