### Setup environment use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use CGI::Session qw/-ip-match/; use DBI; use strict; use warnings; my $dbfile = "/inetpub/wwwroot/data/people1.db"; my $dsn = "dbi:SQLite:dbname=$dbfile"; my $user = ""; my $password = ""; my $dbh = DBI->connect($dsn, $user, $password, { PrintError => 0, RaiseError => 1, AutoCommit => 1, FetchHashKeyName => 'NAME_lc', }); ### Setup session data connection my $cgi = new CGI; my $session = CGI::Session->new("driver:sqlite", undef,{DataSource=>'/inetpub/wwwroot/data/session_management.db'}) or die (CGI::Session->errstr); my $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); ### Test set variables # Skip the logic for authenticating a user for testing purposes only. $session->param("user_logged_in", 'true'); ### Grab SID my $sid = $session->id(); ###For testing only. Basically in previous line did I correctly set the parameter to a flag a user as logged in. my $session_status = $session->param("user_logged_in"); my $login_trials = init(); sub init { #if ( $session->param("~logged-in") ) { # return 1; # if logged in, don't bother going further # } # if we came this far, the login/psswds do not match # the entries in the database my $trials = $session->param("~login-trials") || 0; return $session->param("~login-trials", ++$trials); } ### Print HTML document my $html = "Content-Type: text/html Session Test

Create a new session

Session ID: $sid;

Session status: $session_status;

login_trials: $login_trials;

"; print $html; #### ### Setup environment use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use CGI::Session qw/-ip-match/; use DBI; use strict; use warnings; my $dbfile = "/inetpub/wwwroot/data/people1.db"; my $dsn = "dbi:SQLite:dbname=$dbfile"; my $user = ""; my $password = ""; my $dbh = DBI->connect($dsn, $user, $password, { PrintError => 0, RaiseError => 1, AutoCommit => 1, FetchHashKeyName => 'NAME_lc', }); ### Setup session data connection my $cgi = new CGI; my $sid = $cgi->cookie("CGISESSID") || undef; my $session = CGI::Session->new("driver:sqlite", $sid,{DataSource=>'/inetpub/wwwroot/data/session_management.db'}) or die (CGI::Session->errstr); ### Grab variables from the session my $sid = $session->id(); my $session_status = $session->param("user_logged_in"); my $login_trials = init(); sub init { #if ( $session->param("~logged-in") ) { # return 1; # if logged in, don't bother going further # } # if we came this far, the login/psswds do not match # the entries in the database my $trials = $session->param("~login-trials") || 0; return $session->param("~login-trials", ++$trials); } ### Print HTML document my $html = "Content-Type: text/html Session Test

Check existing session data and status

Session ID: $sid;

Session status: $session_status;

login_trials: $login_trials;

"; print $html;