Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple script to check size of uploaded form data..

Status
Not open for further replies.

quan

Programmer
Oct 3, 2001
58
US
Trying to figure out a simple script that checks the size of submitted form data. Thanks a million <i>Its okay to dream.....</i>
 
Hi quan,

A html form passes a string to a perl script as a single parameter. The string is delimeted into pairs. Each pair hold the name assigned to the input control and the input entered into the control by the user. For example, if I had two text controls named &quot;firstname&quot; and &quot;lastname&quot;, and the user entered &quot;Leland&quot; into &quot;firstname&quot; and &quot;Jackson&quot; into &quot;lastname&quot; the string passed to perl would look something like:

firstname=Leland&lastname=Jackson

Perl captures this info into its buffer. Then perl needs to split the pairs out and assign them to variables. The following script show how a perl script can use the into passed from an html form.

read(STDIN, $buffer , $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs

@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
$value =~ s/~!/ ~!/g;
# Uncomment for debugging purposes
# print &quot;Setting $name to $value<P>&quot;;
$FORM{$name} = $value;
if ($value =~ /\<\!--\#(.*)\s+(.*)\s?=\s?(.*)--\>/) { &kill_input; }
if ($value =~ /[;><\*`\|]/) { &kill_input; }
}

Maybe this will give you some ideas about how you could do what you want.
Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Hi quan,

In the above example the length of the input entered into the html form is 31 per the client browser environment variable CONTENT_LENGTH. Perl can capture this info into variable like $size as follows:

$size=$ENV{'CONTENT_LENGTH'}; Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Sweet, the enviromental variable was what I was looking for.

Thanks a million.

<i>Its okay to dream.....</i>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top