I'm using the CGI libraries:
use CGI qw/:standard/;
use CGI::Validate;
And I'm trying to find a way to be able to parse a get/post request into variables, as well as log the get/post request. Currently, I'm using a series of:
my $variable = param( "var" ) || "OFF";
And it works great for parsing the variables.
After the variable parsing, to log the Get/Post request, I'm using:
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$request = $ENV{'QUERY_STRING'};
}
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $request,$ENV{'CONTENT_LENGTH'})
|| warn "Could not get query\n";
}
##Then Save $request to file.
Works great for get requests, I can parse the variables and log the get request. But with Post requests, I can parse the variables, but the post request doesn't get logged (cause it's already been read in by the variables and there is nothing to readin in). When I move the get/post log function to the top of the param calls, Get still works, and the Post logger works, but I don't get to parse the variables if it's a post cause it's been read into $request.
So using the same functionality as the above with the param() call, is there a better way to do this so that I can both log the full request, AND parse the variables? I was originally doing all of this by hand, but was persuaded into moving to CGI.pm from the board, and am curious if there is a one liner to tell cgi.pm to save the request, AND keep it for parsing..
thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.