hi,
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");
#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://localhost');
what am i doing wrong?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.