logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Perl How to pass POST/GET values to Error 500 handler?

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
consultant



Joined: 29 Mar 2011
Posts: 4

PostPosted: Fri 01 Apr '11 19:00    Post subject: Perl How to pass POST/GET values to Error 500 handler? Reply with quote

I've got a PERL script that handles all my Error 500 Internal Errors by e-mailing me all the HTTP Environment variables.

What I also want to include is all the POST/GET variable values when the error occurred. But because it is a redirect the values are all empty. My script looks like this:

use CGI qw(:all);

print SENDMAIL "ENVIRONMENT VARIABLES: \n";

foreach $key (sort keys(%ENV)) {
print SENDMAIL "$key = $ENV{$key}\n";
}

print SENDMAIL "CGI PUT/GET VARIABLES:\n";

foreach my $p (param()) {
print SENDMAIL "$p=".param($p)."\n";
}

I'm thinking this might be more of an Apache config (.htaccess) issue than a PERL issue but just throwing it out there. My .htaccess says:

ErrorDocument 500 /cgi-bin/error500.cgi

I'm wondering if the only solution is to use some sort of syntax to append all the variable values onto the end?

Or, maybe it is just not possible?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Tue 05 Apr '11 14:39    Post subject: Reply with quote

Code:

sub populateQueryFields {
   %queryString = ();
   my $tmpStr = $ENV{ "QUERY_STRING" };
   @parts = split( /\&/, $tmpStr );
   foreach $part (@parts) {
      ( $name, $value ) = split( /\=/, $part );
      $queryString{ "$name" } = $value;
   }
}


populateQueryFields pulls all name/value pairs from a URL (GET
request) into a hash called %queryString.

Code:

sub populatePostFields {
   %postFields = ();
   read( STDIN, $tmpStr, $ENV{ "CONTENT_LENGTH" } );
   @parts = split( /\&/, $tmpStr );
   foreach $part (@parts) {
      ( $name, $value ) = split( /\=/, $part );
      $value =~ ( s/%23/\#/g );
      $value =~ ( s/%2F/\//g );
      $postFields{ "$name" } = $value;
   }
}


populatePostFields
pulls all data from a POST request (via STDIN) into a hash called
%postFields.

an HTML form->POST request,
Code:

<FORM ACTION="../cgi-bin/script.pl" METHOD="POST">
<INPUT TYPE="TEXT" NAME="fname">
<INPUT TYPE="TEXT" NAME="lname">
...
</FORM>

&populatePostFields;
$firstName = $postFields{ "fname" };
$lastName = $postFields{ "lname" };

Would, once again, pull the respective data entered via the HTML
form into the $firstName and $lastName fields.

One additional note: In the populatePostFields routine, there are
two calls to s///. These are optional, and mimic (lightly) the
functionality of an unEscape() or urlDecode() type of procedure. The
specific two calls made in the routine above replace "%23" with a
pound (#) sign, and "%2F" with a forward slash (/). These can be
altered as you see fit.

found at http://www.howtodothings.com/computers/a1297-how-to-access-get--post-request-data-using-perl.html
Back to top
consultant



Joined: 29 Mar 2011
Posts: 4

PostPosted: Tue 05 Apr '11 16:58    Post subject: Reply with quote

After further investigation what I want to do does not look like it is possible.

The reason is the Custom Error Handler directive for Apache causes apache to redirect and not pass the POST values to the error handler script. It passes just about any other info you could be interested in but not that.

The only way we be to reconfigure the form to submit the values using GET and the variable names and values would be passed in REDIRECT_QUERY_STRING.

See http://httpd.apache.org/docs/2.0/custom-error.html

There are so many different forms and on some dozens of values, this would be a very clunky way to debug as some of the URLs would be HUGE due to the gigantic query string with all the variables.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1