-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformparser.lib
More file actions
46 lines (42 loc) · 903 Bytes
/
Copy pathformparser.lib
File metadata and controls
46 lines (42 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Perl form parser library
# Taken from `Perl in Easy Steps' by Mike McGrath
sub parseform
{
if( $ENV{'REQUEST_METHOD'} eq 'GET' )
{
$pairs = split( /&/, $ENV{'QUERY_STRING'} );
}
elsif( $ENV{'REQUEST_METHOD'} eq 'POST' )
{
read( STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
@pairs = split( /&/, $buffer );
if( $ENV{'QUERY_STRING'} )
{
@getpairs = split( /&/, $ENV{'QUERY_STRING'} );
push( @pairs, @getpairs );
}
}
else
{
print "Content-type:text/html\n\n";
print "Unrecognized Method - Use GET or POST.";
}
foreach $pair( @pairs )
{
( $key, $value ) = split( /=/, $pair );
$key =~ tr/+/ /;
$value =~ tr/+/ /;
$key =~ s/%(..)/pack("c", hex($1))/eg;
$value =~ s/%(..)/pack("c", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g; #ignore SSI
if( $formdata{ $key } )
{
$formdata{$key} .= ", $value";
}
else
{
$formdata{$key} = $value;
}
}
}
1;