i am trying to use cgi::session, but no luck yet. index.html has form which gets user credentials, matches them with mysql databases values, and if right, then sets a session otherwise shows login.html
# create a new session
my $session = CGI::Session->new() or die CGI::Session->errstr;
print $session->header();
#setting session to expire in 1 hour
$session->expire("+1h");
$session->flush();
#further in page
# logout option
print "<a href='logout.cgi'>logout </a></br>";
# check option
print "<a href='check.cgi'>check page</a>"
this page gives output properly, it gnerates session id, but when i click on check page link, it doesn't show me session info and i always get "no session" message.
# cgi page
my $cgi = CGI->new;
#print $cgi->header();
print $cgi->start_html();
print $cgi->p("hello");
print $cgi->cookie('CGISESSID');
# load session info
my $session = CGI::Session->load() or die CGI::Session->errstr;
print $session->header();
if ($session->is_empty)
{
print $cgi->p("no session");
}
else
{
print $cgi->p("<b>session data loaded</b>");
print $session->name;
print $session->id;
print $session->is_expired;
}
print $cgi->end_html();
and this is code in logout.cgi
# Delete the session for good:
my $session = CGI::Session->load() or die CGI::Session->errstr;
$session->delete();
$session->flush();
print $session->header(-location=>'http://login.com');
what am i doing wrong?
How come I am getting two different results.
1. IE9 and Firefox showed started session id, but when clicked on check.cgi IE showed different session id, and Firefox showed none.
2. Both browsers returned, session->is_empty
as true. when check.cgi ran.
When I run scripts from command line mode, it doesn't shows any errors. (returns syntax ok) I am trying to retreive session info from cookie and param but no luck yet.
note: don't want to use frameworks like dancer, catalyst etc, for keeping it simple purpose