#!C:/Perl/bin/perl use strict; use warnings; use CGI::Carp qw( fatalsToBrowser ); use CGI; use CGI::Session; run(); sub run { my $cgi = new CGI(); my $action = $cgi->param('do'); # # Create a session object # my $session = undef; if ($action eq 'login') { # Create a brand new session, by passing an undef cgi argument to CGI::Session. $session = new CGI::Session("driver:File", undef, {Directory=>"/"}); } elsif ($action eq 'stay_logged') { # Keep the existing session, by passing the CGI object to CGI::Session. $session = new CGI::Session("driver:File", $cgi, {Directory=>"/"}); } else { die "Invalid action '$action'\n"; } # # Send the CGISESSID cookie to the browser # my $cookie = undef; my $session_id = undef; if ($session) { $session_id = $session->id(); $cookie = $cgi->cookie(CGISESSID => $session_id); print $cgi->header(-cookie=>$cookie); } print $cgi->start_html('Fooling around with session login/logout'); print "

\$action='$action'

\n"; print "
\$session_id=$session_id\n
\n\n"; print "
\$cookie=$cookie\n\n
\n"; my $random_id = rand(); print "\n"; print $cgi->end_html; }