-------------------------------------------- login.cgi: -------------------------------------------- #!/usr/bin/perl -w use strict; use warnings; use lib "/path/to/lib/"; use CGI; use CGI::Session; # new query object my $cgi = CGI->new; # Get a new session my $session = get_session($cgi); print $session->header(); ... HTML template commands... ... print $template->output(); -------------------------------------------- form.cgi: -------------------------------------------- #!/usr/bin/perl -w use strict; use warnings; use lib "/path/to/lib/"; use CGI; use CGI::Session; # new query object my $cgi = CGI->new; # Get a new session my $session = get_session($cgi); print $session->header(); ... HTML template commands... ... print $template->output(); --------------------------------------------------------- get_session.pm (to create or retrieve a session ) --------------------------------------------------------- sub get_session { my $cgi = shift; my ($session, $exist_sess_id); # Query the cookie and retrieve existing session id, if exists $exist_sess_id = $query->cookie( "CGISESSID" ) or undef; # Retrieve or Create a session $session = CGI::Session->new( undef, $exist_sess_id, { Directory => '/usr/sessions' }) or die "can't create session: $!"; # Set expiration time $session->expire( "+10m" ); return $session; } #### -------------------------------------------- login.cgi (modified) -------------------------------------------- #!/usr/bin/perl -w ... ... # new query object my $cgi = CGI->new; # Load and Delete existing session delete_existing_session($cgi); # Get a new session my $session = get_session($cgi); ... ... -------------------------------------------- delete_existing_session() -------------------------------------------- sub delete_existing_session { my $cgi = shift; my ($session, $exist_sess_id); # Query the cookie and retrieve existing session id, if exists $exist_sess_id = $cgi->cookie( "CGISESSID" ) or undef; # Load existing session $session = CGI::Session->load( $exist_sess_id ); # Delete the session $session->delete(); }