ibjdt
Programmer
- Nov 25, 2002
- 63
i am working on a login system with session ID and cookies, but i have hit a snag - i think with the logout code (below).
the login form accesses the script that shows a success page with 2 links - logout and test.
the logout is supposed to clear and delete the session, expires the cookie and redirect to the login form - i'm not sure the cookie part is correct.
here's the snag -
if i logout, the session file is deleted and i am redirected to the login form, but if i use the browser back button and click the test link it still uses the previous session ID. i want it to give an 'expired' message and link to the login form.
thanks for the help.
the login form accesses the script that shows a success page with 2 links - logout and test.
the logout is supposed to clear and delete the session, expires the cookie and redirect to the login form - i'm not sure the cookie part is correct.
here's the snag -
if i logout, the session file is deleted and i am redirected to the login form, but if i use the browser back button and click the test link it still uses the previous session ID. i want it to give an 'expired' message and link to the login form.
thanks for the help.
Code:
#!/usr/bin/perl
use CGI::Session;
use CGI;
$cgi = new CGI;
$action = $cgi->param('action');
$sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
# LOGOUT
if ($action eq 'logout')
{
$cookie = $cgi->cookie(-name => "CGISESSID");
if ($cookie)
{
CGI::Session->name($cookie);
}
$session = new CGI::Session(undef,$cookie,{'Directory'=>'tmp/sessions'}) or die "$!";
$session->clear();
$session->expire('+2h');
# Remove the session cookie
print "Set-Cookie: session=$id; domain=.$host; path=/; expires=Sat, 8-Oct-2001 01:01:01 GMT\n";
$session->delete();
print $cgi->redirect("[URL unfurl="true"]http://www.domain.com/form.html");[/URL]
}
# TEST PAGE
elsif ($action eq 'test')
{
print $cgi->header();
$cookie = $cgi->cookie(-name => "CGISESSID");
if ( !$cookie ) {
print "Your session expired. Please refresh your browser to re-start your session";
}
else { print "hello s - $sid"; }
}
.....