many thanks for inspiration ;)
sub get_cgi_params_parse ($;$){
my ($str, $params) = @_;
my $res = {};
$str =~ tr/+/ /;
foreach (split /&/, $str){
my ($one, $two) = split /=/, $_;
$one =~ s/%([\da-fA-F][\dA-Fa-f])/pack("C", hex($1))/eg;
$two =~ s/%([\da-fA-F][\dA-Fa-f])/pack("C", hex($1))/eg;
if (exists $res->{$one}){
$res->{$one} .= "\n".$two;
}else{
$res->{$one} = $two;
}
$params->{$one} = $res->{$one};
}
return $res;
}
sub get_cgi_params (;$$$$){
my ($get_str, $post_str, $cookie_str, $force_get) = @_;
my $res = {_names => [], get => {}, post => {}, cookies => {}, vars
+=> {}};
$force_get = 0 unless defined $force_get;
$cookie_str = $ENV{'HTTP_COOKIE'} unless defined $cookie_str;
if ($cookie_str){
foreach (split /; /, $cookie_str){
m/^(.+?)(=(.*))?$/;
$res->{cookies}->{$1} = $3;
}
}
if ($force_get or $ENV{'REQUEST_METHOD'} eq "GET" ){
$get_str = $ENV{'QUERY_STRING'} unless defined $get_str;
$res->{get} = get_cgi_params_parse $get_str, $res->{vars} if $ge
+t_str;
}
if ($ENV{'REQUEST_METHOD'} eq "POST"){
read(STDIN, $post_str, $ENV{'CONTENT_LENGTH'}) unless defined $pos
+t_str;
$res->{post} = get_cgi_params_parse $post_str, $res->{vars} if $po
+st_str;
}
return $res;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|