Leser: 15
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
#!/usr/bin/perl58 -w use strict; use CGI::Carp qw(fatalsToBrowser); use CGI::Session qw/-ip-match/; my %p = (); foreach (split /&/, $ENV{'QUERY_STRING'}) { $p{$1} = $2 if /^([^=]+)=(.+)$/; } if ( not $p{'CGISESSID'} ) { my $SESSION = new CGI::Session("driver:File", undef, {Directory=>"/tmp"}); $SESSION->expire(10000); my $sid = $SESSION->id(); $SESSION->param( 'text_key', 'test_wert' ); print "content-type: text/html\n\n"; print '<a href="sessiontest.pl?CGISESSID='.$sid.'&time='.time.'">sessiontest.pl?CGISESSID='.$sid.'&time='.time.'</a>'; } else { my $SESSION = new CGI::Session("driver:File", $p{'CGISESSID'}, {Directory=>'/tmp'}); print "content-type: text/html\n\n"; print 'CGISESSID from query: '.$p{'CGISESSID'}.'<br />'; print 'Session var "test_key": '.$SESSION->param('text_key').'<br />'; print 'Time elapsed since session was created: '.(time-$p{'time'}).' seconds'; }
sessiontest.pl?CGISESSID=50e958458d79f0282bbb62c35cb24492&time=1258867064
1
2
3
CGISESSID from query: a60a5290f0101bcd16605c06d98ffcba
Session var "test_key": test_wert
Time elapsed since session was created: 1 seconds
1
2
my %p = ();
foreach (split /&/, $ENV{'QUERY_STRING'}) { $p{$1} = $2 if /^([^=]+)=(.+)$/; }
1 2 3 4 5 6 7 8 9 10 11 12 13
our %PARAM = (); my $query = $ENV{'QUERY_STRING'}; read STDIN, $query, $ENV{'CONTENT_LENGTH'} if $ENV{"REQUEST_METHOD"} eq 'POST'; foreach (split /&/, $query) { $PARAM{lc($1)} = &CleanQuery($3) if /^([^=]+)(=(.+))?$/; } sub CleanQuery # param { my $p = shift; $p =~ s/%0D%0A/\n/g; $p =~ tr/+/ /; $p =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; return $p; }
2009-11-22T13:49:38 pqwarum benutzt du eigentlich CGI::Session? du könntest sicher noch ausführungszeit sparen, indem du das selber programmierst.
1
2
3
4
5
# nach dem Laden von CGI::Session
*CGI::Session::atime = sub{
CGI::Session::ctime(@_);
}
1 2 3 4 5 6
# We update the atime by default, but if this (otherwise undocoumented) # parameter is explicitly set to false, we'll turn the behavior off if ( ! defined $update_atime ) { # $self->{_DATA}->{_SESSION_ATIME} = time(); # <-- updating access time # $self->_set_status( STATUS_MODIFIED ); # <-- access time modified above }