http://www.perlmonks.org?node_id=261316


in reply to Detecting a post via cgi

1. `perldoc CGI`
2. See if $ENV{QUERY_STRING} is defined or ne "".
3.
use CGI; use strict; my $cgi = new CGI; my $param1 = ""; $param1 = $cgi->param('textboxonform'); if ($param1 ne "") { #There was data passed from Post/Get }
4. If you are going to use the CGI parameters for anything...do not manually parse the QUERY_STRING. I put that option (#2 above) JIC you only want to know, "Was this script loaded from a Post/Get?"
UPDATE:
5. And if you really want to know which method of parameter passing was used...see fireartist's post above that reads, "my $method = $q->request_method();"

Replies are listed 'Best First'.
Re: Re: Detecting a post via cgi
by Ovid (Cardinal) on May 28, 2003 at 15:08 UTC

    A somewhat cleaner way of doing what you accomplish:

    my $param = $cgi->param('foo') || ''; if ($param) { #... }

    Or, if you always untaint your variables:

    my $_param = $cgi->param('foo') || ''; my ($param) = $_param =~ /^($some_regex)$/;

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

      Very true Ovid. I'm a C programmer...cut me some slack ;o). Seriously though...that's a nice space saver, and I will change my Perl methodology to reflect that 'cleaner' way of instantiation. I post some help to somebody and get help back. Yes, this is a great site.

        No worries. I certainly didn't intend for that to come across as a rebuke. Sometimes people are a little too blunt when they post. I try not to be one of them but it looks like I was :)

        Cheers,
        Ovid

        New address of my CGI Course.
        Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Re: Detecting a post via cgi
by jcpunk (Friar) on May 28, 2003 at 15:11 UTC
    Thanks for the information, but I am unable to get the QUERY_STRNG to be other then "", any thoughts
    my @referers; my $referers; . . . if ($ENV{QUERY_STRING} ne "") { if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer +|i) { &begin_data_parse; } } } else { print "</b>Data Passed Failed Source Check</b>"; } } else { &form; }
    it just keeps calling &form......
      Put QUERY_STRING in quotes just as you did with HTTP_REFERER.