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

I am using Apache 1.3 + mod_perl with perl 5.6.1. Requesting the page test.pl?urlRedirect=TEST which contains this:
use CGI; $query = CGI->new(); my $urlG = $query->url_param("urlRedirect"); my $urlP = $query->param("urlRedirect"); print $query->header, $query->start_html('A Simple Example'); print("CGI version: ".(CGI->VERSION)."<BR>"); print("Url redirect: form=>$urlP, url=>$urlG<BR>");
produces this:
CGI version: 3.09
Url redirect: form=>TEST, url=>TEST
There is NO posted form data though! Help!

Replies are listed 'Best First'.
Re: GET variables overwriting POST variables
by Aristotle (Chancellor) on Nov 16, 2005 at 13:07 UTC

    When you make POST request, CGI::param() uses the POST parameters and ignores the URL. When you make a GET request – as you did – (or HEAD, etc), it uses the URL parameters. Most of the time, this is just fine and is what you want.

    This means that if you do need to know where CGI::param() got its values from, you can check CGI::request_method() to find out.

    Makeshifts last the longest.

Re: GET variables overwriting POST variables
by derby (Abbot) on Nov 16, 2005 at 13:57 UTC

    In order to make param processing DWIM, CGI stores GET and/or POST params into the same internal variable. Here's the relevant bits from CGI:

    # If method is GET or HEAD, fetch the query from # the environment. if ($meth=~/^(GET|HEAD)$/) { if ($MOD_PERL) { $query_string = $self->r->args; } else { $query_string = $ENV{'QUERY_STRING'} if defined $ENV{'QUERY_STRING'}; $query_string ||= $ENV{'REDIRECT_QUERY_STRING'} if defined $ENV{'REDIRECT_QUERY_STRING'}; } last METHOD; } if ($meth eq 'POST') { $self->read_from_client(\$query_string,$content_length,0) if $content_length > 0; # Some people want to have their cake and eat it too! # Uncomment this line to have the contents of the query # string # APPENDED to the POST data. # $query_string .= (length($query_string) ? '&' : '') . # $ENV{'QUERY_STRING'} if defined $ENV{'QUERY_STRING'}; last METHOD; }

    I've always loved that cake comment in CGI

    -derby