#!/usr/local/bin/perl
# This is query_string.pl
# It is a CGI program to decode and display the form
# data from the popcorn Web document
# First produce the header part of the HTML return value
print "Content-type: text/html\n\n";
print "
\n";
print " Display query string data \n";
print "\n";
# Determine the request method and get the query string
$request_method = $ENV{'REQUEST_METHOD'};
if ($request_method eq "GET") {
$query_string = $ENV{'QUERY_STRING'};
}
elsif ($request_method eq "POST") {
read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
}
else {
print "Error - request method is illegal \n";
}
# Split the query string into the name/value pairs
@name_value_pairs = split(/&/, $query_string);
# Split the pairs into names and values and translate the values
# into text (decode hex characters and translate +'s to spaces)
foreach $name_value (@name_value_pairs) {
($name, $value) = split (/=/, $name_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
print "The next name/value pair is: $name, $value \n";
}
# Generate the trailer HTML
print " \n";