Gossamer Forum
Home : General : Perl Programming :

session

Quote Reply
session
i was doing some tests with sessions...
Quote:
CGI::Session->name($scookie);
$session = new CGI::Session("driver:File",$scookie,{'Directory'=>"/home/mysite/cgi-bin/sessions/"}) or die "$!";
if ($session->param('_IDLE_EXPIRY') < time + 120) {
$session->expire('+1m');
print "Content-Type: text/html\n\n";
print('Warn: you were away more then 2 minutes<br>we will take you to the main page.<META HTTP-EQUIV=REFRESH CONTENT="5;URL=/?>');
exit;
} else {
# add 2 minutes to the timer
$session->param('_IDLE_EXPIRY' => time + 120);
}
print "Content-Type: text/html\n\n";
print 'Time: '.$session->param('_IDLE_EXPIRY')."\n";

well its just not working as it should...
The "if" check if the timer is less then "now+2minutes" if it is your session goes to 1 minute expire and youre take to the main page to re-log if not your session is setup with 2+ minutes.
when i login in i am taken to the right message but if i refresh the page i am taken as expired.
i am using the follow code to generate the session:
Quote:
$session = new CGI::Session("driver:File",undef,{'Directory'=>"/home/mysite/cgi-bin/sessions/"});
$session->param('user',"$id");
$session->param('_IDLE_EXPIRY' => time + 120);
$session->expire('+1d');
Quote Reply
Re: [NamedRisk] session In reply to
Are you using '$session -> header ()' to get whatever CGI::Session considers the "proper" headers?

For your expiration purposes, you might consider checking your session's atime (last access time) or ctime (creation time). Though there is no reason to do this since sessions are deleted when they have expired (you could specifically test '$session -> is_empty ()').
Quote Reply
Re: [mkp] session In reply to
But i think for example..

you set up the session to expire in 1 minute then you login.... and after 30 seconds you hit refresh... it should give you anothers 30 seconds that would left you up with that 1 minute start

inst that why sessions stand for to know that you still there and dont expire you until you leave ?

at least thats what i am after ...

anyway ... i can return the sessions and see the content but after 1 minute it just dies ... even if youre navigating...
Quote Reply
Re: [NamedRisk] session In reply to
You can set $session -> expire ('+1m'); so that the session expires 1 minute in the future. If you do this for every request with a valid session, the session will persist as long as the user makes a request once every minute.

In my opinion though, 1 minute is a very short time for a session to expire - at least if there is content. Some people read slower than others, and people can be distracted very easily. I think, depending on your needs, a more liberal amount of time would be safer.

Last edited by:

mkp: Mar 28, 2006, 12:31 AM
Quote Reply
Re: [mkp] session In reply to
the problem of this isnt work was a linux issue eheheh....

the directory where the sessions where been saved didnt had the right permissions so the apache wouldnt update the session as it should.

:)