#! /usr/local/bin/perl # Test any form with this CGI script. # formtest.cgi by David Efflandt (efflandt@xnet.com) # For UNIX systems: # Point the first line of script to your perl. # Upload from DOS|Win as ASCII (not binary or zmodem). # 'chmod 755 filename' from shell (see 'man chmod'). # HTML header print "Content-type: text/html\n\n"; print "Form Test\n\n"; print "

Form Test Results

\n"; # Print POST data if any if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print "


\n

POST Data

\n"; print "

Raw STDIN:

\n"; print "
\n$buffer\n
\n"; &listdata; } # Print GET data (QUERY_STRING) if any if ($ENV{'QUERY_STRING'}) { $buffer = $ENV{'QUERY_STRING'}; print "


\n

GET data

\n"; print "

Raw QUERY_STRING:

\n"; print "
\n$buffer\n
\n"; &listdata; } # No Data response unless ($buffer) { print "


\n

No Form Data Submitted

\n"; print "This script will display any form data submitted "; print "to it using the GET or POST method.\n"; exit; } print "

\n"; # List the variables sub listdata { print "

Variables:

\n"; # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Plain text values # print "

$name:

$value
\n"; # HTML values print "

$name = $value\n"; } }