Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Using CGI.pm, is there any reason why a form POST will work fine, but a GET will not. When this script is run with POST it works, however using GET no data is passed.
#!/usr/local/bin/perl use DBI; use CGI; require "iniappresp.pl"; $| = 1; $debug = 2; $query = new CGI; $startdate = $query->param('date'); $location = $query->param('location'); #$app = $query->param('application'); $begin = $query->param('start'); $stop = $query->param('end'); $begin = '0'.$begin if($begin < 10); $stop = '0'.$stop if($stop < 10); $startdate =~ m%(.*)/(.*)/(.*)%; $month = $1; $day = $2; $year = $3;

Replies are listed 'Best First'.
(Ovid) Re: CGI POST vs. GET problem
by Ovid (Cardinal) on Jun 06, 2001 at 04:12 UTC

    Could you post the HTML? Checking out your form tag might help (I'm wondering offhand if you are using and enctype of "multipart/form-data" I think doesn't work with GET. I'll have to double check).

    Your GET data should be in %ENV{ 'QUERY_STRING' }. Try printing that directly to the screen. If it doesn't have anything, then your GET data is not being sent. You could also check your server access logs as that will contain the query string if you use GET.

    Other comments: You haven't used warnings, strict, or taint checking. Perhaps this is just a minimal test case you're showing us, but these issues are very important.

    Final note: your regular expression could use some work. Right now, if someone types an extra forward slash, it will break. Assuming that you only have numbers for month, day, and year (with a four digit year), the following regex will work better:

    my ( $month, $day, $year ) = ( $startdate =~ m%(\d\d)/(\d\d)/(\d\d\d\d +)% );

    See Death to Dot Star! for details.

    My apologies if this post seems like overkill!

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: CGI POST vs. GET problem
by Trimbach (Curate) on Jun 06, 2001 at 06:33 UTC
    The last time I had a "GET works-- POST doesn't" problem it was because I was using Basic Authentication and hadn't adjusted my .htaccess file to allow for POST requests. That is, if your .htaccess looks something like this:
    <Limit GET> require valid-user </Limit>
    You ain't gonna get no POSTs processed.

    Gary Blackburn
    Trained Killer

Re: CGI POST vs. GET problem
by dws (Chancellor) on Jun 06, 2001 at 03:40 UTC
      require "iniappresp.pl"; What does iniappresp.pl do, and does moving it some place below   $query = new CGI; make any difference?

      mmm moving the require statement made it work. Must have been that %ENV hash I had in it. thanks guys.
Re: CGI POST vs. GET problem
by olly (Scribe) on Jun 06, 2001 at 03:21 UTC
    As far as I know CGI.PM doesn't differ about post or get, that is one of the nice things about it. Maybe you can show your post and get html, also look at the url after the posting with the get method see if you have var=value pairs in it.

    Imagination is more important then knowledge -Einstein-

Re: CGI POST vs. GET problem
by shotgunefx (Parson) on Jun 06, 2001 at 08:45 UTC
    How are you URL encoding the get? I believe the latest versions of CGI use ; to seperate parameters instead of & unless you specificially tell it other wise. Checking the $ENV{QUERY_STING}and GET access as stated above are both two things you should check.

    -Lee

    "To be civilized is to deny one's nature."
      Looking in the version of CGI.pm that I have on my server, it shows the following:
      sub parse_params { my($self,$tosplit) = @_; my(@pairs) = split(/[&;]/,$tosplit); my($param,$value); etc.
      The use of the & or ; in the split should mean that CGI will work for browsers using & to separate pairs as well as working for browsers using ; to separate pairs.

      Claude

        I'd look to make sure you are getting passed the QUERY_STRING.

        Then I would look at the server config to make sure GET is enabled.

        -Lee

        "To be civilized is to deny one's nature."