• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

perl, how to print out all the cgi fom values

how do I print out all the form values?
0
rgbcof
Asked:
rgbcof
1 Solution
 
sjklein42Commented:
Try this.  You may need to fix the first line in the file depending on your server setup.

(try it here: http://www.sjklein.com/dumpParms.pl?foo=bar&bar2=foo)

#!/usr/bin/perl -w

sub HttpUnescape
{
	my $x = shift (@_);
	my $y = '';
	$x =~ s/\+/ /g;			# restore blank characters
	while ( $x =~ /\%([0123456789ABCDEF][0123456789ABCDEF])/i ) { $y .= $` . chr (hex($1)); $x = $'; }
	return $y . $x;
}

sub GetArgs
{
	$x = $ENV{'REQUEST_URI'};
	if ( $x =~ /\?/ ) { $x = $'; }			# split at ?, if any, and keep second part
	if ( $x =~ /\/\&/ ) { $x = $'; }		# split at /&, if any, and keep second part
	$x =~ s/^\///;							# trim leading slash, if any
	$x =~ s/^\&//;							# trim leading &, if any

	@argpairs = split (/\&/, $x);
	foreach $argpair (@argpairs)
	{
		if ( $argpair =~ /\=/ )
		{ 
			$key = lc($`);			# all argument are lower case

			$x = HttpUnescape($');
			$x =~ s/^\s+//;			# remove leading space
			$x =~ s/\s+$//;			# remove trailing space
			$x =~ s/\s+/ /g;		# normalize whitespace
			$arg{$key} = $x;
		}
		else { $arg{$argpair} = 1; }
	}
}

sub GetPostParms
{
	$postData = join ('', <>);
	@postParms = split (/\&/, $postData);

	foreach $postParm (@postParms)
	{
		($parmName, $x) = split(/\=/, $postParm);
		$x = HttpUnescape($x);
		$x =~ s/\r//g;
		$postParm{$parmName} = $x;
	}
}

GetArgs();
GetPostParms();

print q{Content-type: text/html

<html><body><pre>};

foreach $key (sort(keys(%ENV))) { print "ENV $key = $ENV{$key}\n"; }
print '<hr>';
foreach $key (sort(keys(%arg))) { print "CGIARG $key = $arg{$key}\n"; }
print '<hr>';
foreach $parmName (sort(keys(%postParm))) { print "POSTPARM $parmName = $postParm{$parmName}\n"; }

print q{</body></html>};

Open in new window

0
 
rgbcofAuthor Commented:
wow, very detailed answer.   Thanks,
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now