Solved

perl, how to print out all the cgi fom values

Posted on 2011-02-15
2
526 Views
Last Modified: 2013-12-25
how do I print out all the form values?
0
Comment
Question by:rgbcof
2 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 250 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;
	}
}

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
 

Author Closing Comment

by:rgbcof
ID: 34899803
wow, very detailed answer.   Thanks,
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now