beginners-cgi:
I have a Debian 6.0, Apache 2.2.16, Perl 5.10.1, and CGI.pm 3.43 machine
with a folder containing:
$ cat .htaccess
Options +ExecCGI
AddHandler cgi-script pl
ErrorDocument 404 /cgi.pm-get-post-errordocument/printcgi.pl
$ cat index.html
<html>
<body>
<ul>
<li>direct:
<ul>
<li>GET
<form action="printcgi.pl" method="GET">
<input name="inputText" type="text">
<input name="inputSubmit" type="submit">
</form>
</li>
<li>POST
<form action="printcgi.pl" method="POST">
<input name="inputText" type="text">
<input name="inputSubmit" type="submit">
</form>
</li>
</ul>
</li>
<li>ErrorDocument:
<ul>
<li>GET
<form action="nosuchfile.pl" method="GET">
<input name="inputText" type="text">
<input name="inputSubmit" type="submit">
</form>
</li>
<li>POST
<form action="nosuchfile.pl" method="POST">
<input name="inputText" type="text">
<input name="inputSubmit" type="submit">
</form>
</li>
</ul>
</li>
</ul>
</body>
</html>
$ cat printcgi.pl
#! /usr/bin/perl
use strict;
use warnings;
use CGI;
use Data::Dumper;
use IO::Scalar;
$Data::Dumper::Sortkeys = 1;
my $stdin = join '', <STDIN>;
my $s;
tie *STDIN, 'IO::Scalar', \$s;
print STDIN $stdin;
tied(*STDIN)->setpos(0);
my $q= CGI::new();
print $q->header('text/plain'),
Data::Dumper->Dump([$0, \@ARGV, $stdin, \%ENV, $q],
[qw(0 *ARGV STDIN *ENV q)]);
When I browse to index.html, enter data in the text boxes, and click the
submit buttons, the first case (direct hit, GET) works as expected:
$0 =
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl';
@ARGV = ();
$STDIN = '';
%ENV = (
'DOCUMENT_ROOT' => '/home/dpchrist/sandbox/apache2/public_html',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'apache2-sandbox-p43400e.holgerdanske.com',
'HTTP_KEEP_ALIVE' => '300',
'HTTP_REFERER' =>
'http://apache2-sandbox-p43400e.holgerdanske.com/cgi.pm-get-post-errordocument/',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.1.16) Gecko/20110302 Iceweasel/3.5.16 (like Firefox/3.5.16)',
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'QUERY_STRING' => 'inputText=direct+GET&inputSubmit=Submit+Query',
'REMOTE_ADDR' => '192.168.0.34',
'REMOTE_PORT' => '58809',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' =>
'/cgi.pm-get-post-errordocument/printcgi.pl?inputText=direct+GET&inputSubmit=Submit+Query',
'SCRIPT_FILENAME' =>
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl',
'SCRIPT_NAME' => '/cgi.pm-get-post-errordocument/printcgi.pl',
'SERVER_ADDR' => '192.168.0.34',
'SERVER_ADMIN' => '[no address given]',
'SERVER_NAME' => 'apache2-sandbox-p43400e.holgerdanske.com',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '<address>Apache/2.2.16 (Debian) Server
at apache2-sandbox-p43400e.holgerdanske.com Port 80</address>
',
'SERVER_SOFTWARE' => 'Apache/2.2.16 (Debian)'
);
$q = bless( {
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'.header_printed' => 1,
'.parameters' => [
'inputText',
'inputSubmit'
],
'escape' => 1,
'param' => {
'inputSubmit' => [
'Submit Query'
],
'inputText' => [
'direct GET'
]
},
'use_tempfile' => 1
}, 'CGI' );
The second case (direct hit, POST) works as expected:
$0 =
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl';
@ARGV = ();
$STDIN = 'inputText=direct+POST&inputSubmit=Submit+Query';
%ENV = (
'CONTENT_LENGTH' => '46',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'DOCUMENT_ROOT' => '/home/dpchrist/sandbox/apache2/public_html',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'apache2-sandbox-p43400e.holgerdanske.com',
'HTTP_KEEP_ALIVE' => '300',
'HTTP_REFERER' =>
'http://apache2-sandbox-p43400e.holgerdanske.com/cgi.pm-get-post-errordocument/',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.1.16) Gecko/20110302 Iceweasel/3.5.16 (like Firefox/3.5.16)',
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'QUERY_STRING' => '',
'REMOTE_ADDR' => '192.168.0.34',
'REMOTE_PORT' => '58810',
'REQUEST_METHOD' => 'POST',
'REQUEST_URI' => '/cgi.pm-get-post-errordocument/printcgi.pl',
'SCRIPT_FILENAME' =>
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl',
'SCRIPT_NAME' => '/cgi.pm-get-post-errordocument/printcgi.pl',
'SERVER_ADDR' => '192.168.0.34',
'SERVER_ADMIN' => '[no address given]',
'SERVER_NAME' => 'apache2-sandbox-p43400e.holgerdanske.com',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '<address>Apache/2.2.16 (Debian) Server
at apache2-sandbox-p43400e.holgerdanske.com Port 80</address>
',
'SERVER_SOFTWARE' => 'Apache/2.2.16 (Debian)'
);
$q = bless( {
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'.header_printed' => 1,
'.parameters' => [
'inputText',
'inputSubmit'
],
'escape' => 1,
'param' => {
'inputSubmit' => [
'Submit Query'
],
'inputText' => [
'direct POST'
]
},
'use_tempfile' => 1
}, 'CGI' );
The third case (ErrorDocument, GET) works as expected:
$0 =
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl';
@ARGV = ();
$STDIN = '';
%ENV = (
'DOCUMENT_ROOT' => '/home/dpchrist/sandbox/apache2/public_html',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'apache2-sandbox-p43400e.holgerdanske.com',
'HTTP_KEEP_ALIVE' => '300',
'HTTP_REFERER' =>
'http://apache2-sandbox-p43400e.holgerdanske.com/cgi.pm-get-post-errordocument/',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.1.16) Gecko/20110302 Iceweasel/3.5.16 (like Firefox/3.5.16)',
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'QUERY_STRING' => '',
'REDIRECT_QUERY_STRING' =>
'inputText=ErrorDocument+GET&inputSubmit=Submit+Query',
'REDIRECT_REQUEST_METHOD' => 'GET',
'REDIRECT_STATUS' => '404',
'REDIRECT_URL' => '/cgi.pm-get-post-errordocument/nosuchfile.pl',
'REMOTE_ADDR' => '192.168.0.34',
'REMOTE_PORT' => '55219',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' =>
'/cgi.pm-get-post-errordocument/nosuchfile.pl?inputText=ErrorDocument+GET&inputSubmit=Submit+Query',
'SCRIPT_FILENAME' =>
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl',
'SCRIPT_NAME' => '/cgi.pm-get-post-errordocument/printcgi.pl',
'SERVER_ADDR' => '192.168.0.34',
'SERVER_ADMIN' => '[no address given]',
'SERVER_NAME' => 'apache2-sandbox-p43400e.holgerdanske.com',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '<address>Apache/2.2.16 (Debian) Server
at apache2-sandbox-p43400e.holgerdanske.com Port 80</address>
',
'SERVER_SOFTWARE' => 'Apache/2.2.16 (Debian)'
);
$q = bless( {
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'.header_printed' => 1,
'.parameters' => [
'inputText',
'inputSubmit'
],
'escape' => 1,
'param' => {
'inputSubmit' => [
'Submit Query'
],
'inputText' => [
'ErrorDocument GET'
]
},
'use_tempfile' => 1
}, 'CGI' );
But the fourth case (ErrorDocument, POST) does not work as expected --
CGI.pm doesn't see the query parameters available on STDIN:
$0 =
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl';
@ARGV = ();
$STDIN = 'inputText=ErrorDocument+POST&inputSubmit=Submit+Query';
%ENV = (
'CONTENT_LENGTH' => '53',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'DOCUMENT_ROOT' => '/home/dpchrist/sandbox/apache2/public_html',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'apache2-sandbox-p43400e.holgerdanske.com',
'HTTP_KEEP_ALIVE' => '300',
'HTTP_REFERER' =>
'http://apache2-sandbox-p43400e.holgerdanske.com/cgi.pm-get-post-errordocument/',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.1.16) Gecko/20110302 Iceweasel/3.5.16 (like Firefox/3.5.16)',
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'QUERY_STRING' => '',
'REDIRECT_REQUEST_METHOD' => 'POST',
'REDIRECT_STATUS' => '404',
'REDIRECT_URL' => '/cgi.pm-get-post-errordocument/nosuchfile.pl',
'REMOTE_ADDR' => '192.168.0.34',
'REMOTE_PORT' => '55220',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/cgi.pm-get-post-errordocument/nosuchfile.pl',
'SCRIPT_FILENAME' =>
'/home/dpchrist/sandbox/apache2/public_html/cgi.pm-get-post-errordocument/printcgi.pl',
'SCRIPT_NAME' => '/cgi.pm-get-post-errordocument/printcgi.pl',
'SERVER_ADDR' => '192.168.0.34',
'SERVER_ADMIN' => '[no address given]',
'SERVER_NAME' => 'apache2-sandbox-p43400e.holgerdanske.com',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '<address>Apache/2.2.16 (Debian) Server
at apache2-sandbox-p43400e.holgerdanske.com Port 80</address>
',
'SERVER_SOFTWARE' => 'Apache/2.2.16 (Debian)'
);
$q = bless( {
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'.header_printed' => 1,
'.parameters' => [],
'escape' => 1,
'param' => {},
'use_tempfile' => 1
}, 'CGI' );
I would like the error handler script to be able to see the POST
parameters via CGI.pm.
Any suggestions?
TIA,
David
--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/