|
#
Replace this line with your path to perl
#!/usr/local/bin/perl
# This line sets the method that this script was accessed
(GET or POST)
my $method = $ENV{'REQUEST_METHOD'};
# The following is a basic if else structure to use
the appropriate
# processing for grabbing the form data
if ($method eq "GET") {
$rawdata = $ENV{'QUERY_STRING'};
} else {
# if not "GET" then it will
default "POST"
read(STDIN, $rawdata, $ENV{'CONTENT_LENGTH'});
}
# Splits the data pairs into sections
my @value_pairs = split (/&/,$rawdata);
my %formdata = ();
# Cycles through each pair to grab the values of the
fields
foreach $pair (@value_pairs) {
($field, $value) = split (/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack
("C", hex ($1))/eg;
$formdata{$field} = $value;
# store the field data in the results
hash
}
# next line sets the MIME type for the output
print "Content-type: text/html\n\n";
# cycle through the results and print each field/value
foreach $field (sort keys(%formdata)) {
print "$field has value $formdata{$field}\n";
}
|