Farid Hajji: Perl - Einführung, Anwendungen, Referenz
2., aktualisierte und erweiterte Auflage
Addison-Wesley Longman, ISBN 3-8273-1535-2
cgi-s-cookie.pl
#!/usr/local/bin/perl -w
# cgi-s-cookie.pl -- Zustandserhaltung mit Cookies.
use strict;
use CGI qw(:standard);
use CGI::Cookie;
my $state = retrieve_state();
my $nextstate = compute_next_state($state);
my $saveaction = save_state($nextstate);
# Tue etwas abhaengig von $state:
print header(-cookie => $saveaction),
start_html('State with Cookies'),
"Current state: ", $state, p,
"If you call me again, I'll increment it for you",
end_html;
use constant INITSTATE => 1;
use constant STATENAME => 'mystate';
sub retrieve_state {
my $state = cookie(-name => STATENAME) || INITSTATE;
return $state;
}
sub compute_next_state {
my $current_state = shift;
return $current_state + 1;
}
sub save_state {
my $newstate = shift;
my $cookie = new CGI::Cookie(-name => STATENAME,
-value => $newstate,
-expires => '+5m');
return $cookie;
}
[Prev] [Up] [Relevant Chapter] [Next]
[Alte Quelle]
| Last modified: $Date: 2006/05/18 12:55:53 $ FH. Search :: Sitemap :: Disclaimer :: Copyright :: Privacy |
|