programming-examples/perl/CGI/Learn about the current CGI request.pl

59 lines
1.5 KiB
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "The command line arguments for this script are:\n";
print join(" ",@ARGV),"\n\n";
print "The request information available to the script includes:\n\n";
print "REQUEST_METHOD = ",$ENV{"REQUEST_METHOD"},"\n";
print "PATH_INFO = " ,$ENV{"PATH_INFO"},"\n";
print "PATH_TRANSLATED = " ,$ENV{"PATH_TRANSLATED"},"\n";
print "SCRIPT_NAME = " ,$ENV{"SCRIPT_NAME"},"\n";
print "QUERY_STRING = " ,$ENV{"QUERY_STRING"},"\n";
print "CONTENT_TYPE = ",$ENV{"CONTENT_TYPE"},"\n";
print "CONTENT_LENGTH = ",$ENV{"CONTENT_LENGTH"},"\n\n";
if($ENV{"REQUEST_METHOD"} eq "POST")
{
$contentLength = $ENV{"CONTENT_LENGTH"};
if($contentLength)
{
read(STDIN,$queryString,$contentLength);
}
else
{
$queryString = "";
}
print "Standard in is:\n";
print $queryString;
print "\n";
}
1;
#############################################
<HTML>
<HEAD>
<TITLE>Request Initiator</TITLE>
</HEAD>
<BODY>
<H1>GET Form</H1>
<FORM ACTION="index.pl" METHOD=GET>
<INPUT TYPE="TEXT" SIZE=60 NAME="DATA">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SUBMIT">
</FORM>
<BR><BR>
<H1>POST Form</H1>
<FORM ACTION="PerlCGI/requestinfo.pl" METHOD=POST>
<INPUT TYPE="TEXT" SIZE=60 NAME="DATA">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SUBMIT">
</FORM>
</BODY>
</HTML>