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; }
In reply to Re: Get those parameters without CGI.pm
by Anonymous Monk
in thread Get those parameters without CGI.pm
by j.a.p.h.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |