perl, how to print out all the cgi fom values

Posted on 2011-02-15
Medium Priority
Last Modified: 2013-12-25
how do I print out all the form values?
Question by:rgbcof
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Accepted Solution

sjklein42 earned 1000 total points
ID: 34899088
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;


print q{Content-type: text/html


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


Author Closing Comment

ID: 34899803
wow, very detailed answer.   Thanks,

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question