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

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

Hello guys !

I have a CGI script, and I'v been wanting to know if there's a way to know if a parameter I got from the browser, was sent to me in POST or GET method.

Anyone?

Hotshot

Replies are listed 'Best First'.
Re: post and get
by blakem (Monsignor) on Mar 18, 2002 at 08:16 UTC
    Check the value of $ENV{REQUEST_METHOD}

    -Blake

Re: post and get
by busunsl (Vicar) on Mar 18, 2002 at 08:25 UTC
    Use the CGI module and you don't have to bother about the request method.
    But if you need it anyway, use CGI's request_method() function.
Re: post and get
by tomhukins (Curate) on Mar 18, 2002 at 09:53 UTC
Re: post and get
by Juerd (Abbot) on Mar 18, 2002 at 09:53 UTC

    was sent to me in POST or GET method.

    Blake already gave a perfect answer, but I'd like to add that %ENV is loaded with useful information. Give the following piece of code a try to find out more about this wonderful hash.

    use Data::Dumper; print Dumper \%ENV;

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

Re: post and get
by newrisedesigns (Curate) on Mar 18, 2002 at 22:08 UTC

    Whenever you write something in Perl for use as a CGI application, it's always best to use CGI.pm. The module is in almost every distrobution, and it doesn't cause too much of a delay (if speed is your concern.)

    CGI.pm will also handle your queries for you, and can determine GET from POST and vice-versa.

    All the instructions for use are right here, and I'm sure any monk here will help you if you need it.

    Hope this helps.

    John J Reiser
    newrisedesigns.com