Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > cgi.pm distinguish between POST & GET

Reply
Thread Tools

cgi.pm distinguish between POST & GET

 
 
mike_solomon@lineone.net
Guest
Posts: n/a
 
      03-01-2006
I am using the CGI module and can get access to the POST & GET
variables

use CGI;
#create new cgi
my $m_cgi = new CGI;

#put cgi data into hash
my %m_cgi_data = $m_cgi->Vars;

What I would like todo is find some way of knowing whether a variable
is from a GET or a POST as for one form I would like to ignore GET's

Is this possible using cgi.pm?

Thanks

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      03-01-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am using the CGI module and can get access to the POST & GET
> variables
>
> use CGI;
> #create new cgi
> my $m_cgi = new CGI;
>
> #put cgi data into hash
> my %m_cgi_data = $m_cgi->Vars;
>
> What I would like todo is find some way of knowing whether a variable
> is from a GET or a POST as for one form I would like to ignore GET's
>
> Is this possible using cgi.pm?


Have you read:
http://perldoc.perl.org/CGI.html#MIX...URL-PARAMETERS
?

Paul Lalli

 
Reply With Quote
 
 
 
 
mike_solomon@lineone.net
Guest
Posts: n/a
 
      03-01-2006

Paul Lalli wrote:

> (E-Mail Removed) wrote:
> > I am using the CGI module and can get access to the POST & GET
> > variables
> >
> > use CGI;
> > #create new cgi
> > my $m_cgi = new CGI;
> >
> > #put cgi data into hash
> > my %m_cgi_data = $m_cgi->Vars;
> >
> > What I would like todo is find some way of knowing whether a variable
> > is from a GET or a POST as for one form I would like to ignore GET's
> >
> > Is this possible using cgi.pm?

>
> Have you read:
> http://perldoc.perl.org/CGI.html#MIX...URL-PARAMETERS
> ?
>
> Paul Lalli


yup read it before I posted

either I am not understanding it properly or it doesn't work for me

using url_param & param both returned a GET parameter

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-01-2006
"(E-Mail Removed)" <(E-Mail Removed)> wrote:
> >
> > Have you read:
> > http://perldoc.perl.org/CGI.html#MIX...URL-PARAMETERS
> > ?
> >
> > Paul Lalli

>
> yup read it before I posted
>
> either I am not understanding it properly or it doesn't work for me


Well, that sucks. It does work for me, so I probably understand it
properly. If you showed us some code, maybe I could understand your
misunderstanding and correct it.


> using url_param & param both returned a GET parameter


So then you know it is from the query string in the URL. Isn't that what
you wanted to know? Doesn't that solve your problem?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
mike_solomon@lineone.net
Guest
Posts: n/a
 
      03-01-2006

(E-Mail Removed) wrote:

> Paul Lalli wrote:
>
> > (E-Mail Removed) wrote:
> > > I am using the CGI module and can get access to the POST & GET
> > > variables
> > >
> > > use CGI;
> > > #create new cgi
> > > my $m_cgi = new CGI;
> > >
> > > #put cgi data into hash
> > > my %m_cgi_data = $m_cgi->Vars;
> > >
> > > What I would like todo is find some way of knowing whether a variable
> > > is from a GET or a POST as for one form I would like to ignore GET's
> > >
> > > Is this possible using cgi.pm?

> >
> > Have you read:
> > http://perldoc.perl.org/CGI.html#MIX...URL-PARAMETERS
> > ?
> >
> > Paul Lalli

>
> yup read it before I posted
>
> either I am not understanding it properly or it doesn't work for me
>
> using url_param & param both returned a GET parameter


OK done some further tests

param returns both GET & POST

url_param returns GET

what I want is just POST but now I understand I can exclude anything in
url_param

Thanks for replying

 
Reply With Quote
 
Karlheinz Weindl
Guest
Posts: n/a
 
      03-01-2006
(E-Mail Removed) schrieb:

> I am using the CGI module and can get access to the POST & GET
> variables
>
> use CGI;
> #create new cgi
> my $m_cgi = new CGI;
>
> #put cgi data into hash
> my %m_cgi_data = $m_cgi->Vars;
>
> What I would like todo is find some way of knowing whether a variable
> is from a GET or a POST as for one form I would like to ignore GET's
>
> Is this possible using cgi.pm?


How about using request_method() to find out how your script was called?

Kh
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-01-2006
"(E-Mail Removed)" <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>
> > Paul Lalli wrote:
> >
> > > (E-Mail Removed) wrote:
> > > > I am using the CGI module and can get access to the POST & GET
> > > > variables
> > > >
> > > > use CGI;
> > > > #create new cgi
> > > > my $m_cgi = new CGI;
> > > >
> > > > #put cgi data into hash
> > > > my %m_cgi_data = $m_cgi->Vars;
> > > >
> > > > What I would like todo is find some way of knowing whether a
> > > > variable is from a GET or a POST as for one form I would like to
> > > > ignore GET's
> > > >
> > > > Is this possible using cgi.pm?
> > >
> > > Have you read:
> > > http://perldoc.perl.org/CGI.html#MIX...URL-PARAMETERS
> > > ?
> > >
> > > Paul Lalli

> >
> > yup read it before I posted
> >
> > either I am not understanding it properly or it doesn't work for me
> >
> > using url_param & param both returned a GET parameter

>
> OK done some further tests
>
> param returns both GET & POST


Ah, now I see the problem.
No, param returns either GET or POST--but not both--for any one form
submission.

> url_param returns GET


If the form was submitted with GET, both param and url_param return the
parameters from the URL.

If the form was submitted with POST but also had URL parameters thrown in
too, then param returns only the POSTed parameteters and url_param returns
only the URL ones.


> what I want is just POST but now I understand I can exclude anything in
> url_param



If the form was submitted with POST, then the exclusion has already
been done for you in param(), and you don't need to use url_param. If the
form was submitted with GET, then you could just throw up a "drop dead,
hacker" page and never even look at param.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      03-01-2006
>>>>> "x" == xhoster <(E-Mail Removed)> writes:

x> "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>
>> param returns both GET & POST


x> Ah, now I see the problem.
x> No, param returns either GET or POST--but not both--for any one form
x> submission.

cgi.pm supports having both get (in the url) and post params on the same
cgi call. it will mix the params from both sources. i am not sure which
will override the other (if that happens). from cgi.pm:

$query = new CGI;

This will parse the input (from both POST and GET methods)
and store it into a perl5 object called $query.

note the 'both' in there.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      03-02-2006
>>>>> "x" == xhoster <(E-Mail Removed)> writes:

x> Uri Guttman <(E-Mail Removed)> wrote:
>> >>>>> "x" == xhoster <(E-Mail Removed)> writes:

>>

x> "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>> >>
>> >> param returns both GET & POST

>>

x> Ah, now I see the problem.
x> No, param returns either GET or POST--but not both--for any one form
x> submission.
>>
>> cgi.pm supports having both get (in the url) and post params on the same
>> cgi call. it will mix the params from both sources.


x> Do you have example code to demonstrate that?

>> i am not sure which
>> will override the other (if that happens). from cgi.pm:
>>
>> $query = new CGI;
>>
>> This will parse the input (from both POST and GET methods)

^^^^^^^^^^^^^^^

>> and store it into a perl5 object called $query.

^^^^^^^^^^^^^
>>
>> note the 'both' in there.


x> I note the 'both', but I do not the 'in one form submission'. Quite the
x> opposite:

also note the underlined parts above.

x> MIXING POST AND URL PARAMETERS
x> ...
x> It is possible for a script to receive CGI parameters in the URL as
x> well as in the fill-out form by creating a form that POSTs to a URL
x> containing a query string (a "?" mark followed by arguments). The
x> param() method will always return the contents of the POSTed
x> fill-out form, ignoring the URL's query string.

i never said anything about access params from both get/post. i just was
pointing out that you can use both and cgi.pm will handle it. dealing
with both in a submission is up to you but you can get both sets of
params if desired.

<snip of cgi script i won't run>

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
mike_solomon@lineone.net
Guest
Posts: n/a
 
      03-02-2006

(E-Mail Removed) wrote:

> (E-Mail Removed) wrote:
>
> > Paul Lalli wrote:
> >
> > > (E-Mail Removed) wrote:
> > > > I am using the CGI module and can get access to the POST & GET
> > > > variables
> > > >
> > > > use CGI;
> > > > #create new cgi
> > > > my $m_cgi = new CGI;
> > > >
> > > > #put cgi data into hash
> > > > my %m_cgi_data = $m_cgi->Vars;
> > > >
> > > > What I would like todo is find some way of knowing whether a variable
> > > > is from a GET or a POST as for one form I would like to ignore GET's
> > > >
> > > > Is this possible using cgi.pm?
> > >
> > > Have you read:
> > > http://perldoc.perl.org/CGI.html#MIX...URL-PARAMETERS
> > > ?
> > >
> > > Paul Lalli

> >
> > yup read it before I posted
> >
> > either I am not understanding it properly or it doesn't work for me
> >
> > using url_param & param both returned a GET parameter

>
> OK done some further tests
>
> param returns both GET & POST
>
> url_param returns GET
>
> what I want is just POST but now I understand I can exclude anything in
> url_param
>
> Thanks for replying



I have added the following code to remove any GET - seems to do what I
want

#create new cgi
$m_cgi = new CGI;

#put cgi data into hash
%m_cgi_data = $m_cgi->Vars;

#remove GET from hash
for my $key (keys %m_cgi_data ) {
delete $m_cgi_data{$key} if $m_cgi->url_param($key);
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to distinguish between heap/stack pointers Sayan C++ 6 02-09-2004 04:13 PM
How to distinguish between Events and States? Vinodh Kumar P C++ 1 12-12-2003 01:42 AM
distinguish between char* and char[x] mosfet C++ 6 11-27-2003 01:28 AM
How to distinguish between Olympus refurbished and new? Jerry Nash Digital Photography 4 11-19-2003 05:22 PM
Way to distinguish between POST and GET data in Python CGIs? Simon Willison Python 1 08-28-2003 09:32 AM



Advertisments