Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Answer: How do I get at the parameters in my CGI program?

by turnstep (Parson)
on Mar 29, 2000 at 21:10 UTC ( #6432=categorized answer: print w/replies, xml ) Need Help??

Q&A > CGI programming > How do I get at the parameters in my CGI program? - Answer contributed by turnstep

Here's a way to do "by hand":

Please don't do this. It is shown here for illustrative purposes only

## First, grab any GET stuff (overrrides POST) if ($ENV{'REQUEST_METHOD'} eq "GET") { $sinstring = $ENV{'QUERY_STRING'} } ## Could change this to a simple "if" to allow GET *and* POST elsif ($ENV{'REQUEST_METHOD'} eq 'POST' && $ENV{'CONTENT_TYPE'} eq "application/x-www-form-urlencoded") { ## Okay if CONTENT_LENGTH is 0... read(STDIN, $sinstring, $ENV{CONTENT_LENGTH}); } else { ## Last ditch efforts, no REQUEST METHOD found ## Any GET info? $sinstring = $ENV{'QUERY_STRING'}; ## Any POST info? $sinstring || read(STDIN, $sinstring, $ENV{CONTENT_LENGTH}); } ## Find all of our sins: for (split(/\&/, $sinstring)) { if (($sin_name, $sin_val) = /(.*)=(.*)/) { ## Normal... $sin_val =~ tr/+/ /; $sin_val =~ s/%(..)/pack('c',hex($1))/eg; } else { ## Abnormal... $sin_name = $_; $sin_val = "0"; } $sin_name =~ tr/+/ /; $sin_name =~ s/%(..)/pack('c',hex($1))/eg; $sins++; if (defined $sin{$sin_name}) { ## Allows for "0" cases.... $sin{$sin_name} .= '#' . $sin_val; } else { $sin{$sin_name} = $sin_val; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2020-04-05 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (33 votes). Check out past polls.

    Notices?