Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Detecting a post via cgi

by cbro (Pilgrim)
on May 28, 2003 at 14:44 UTC ( #261316=note: print w/ replies, xml ) Need Help??


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();"


Comment on Re: Detecting a post via cgi
Download Code
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://261316]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (17)
As of 2014-07-23 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (144 votes), past polls