Posted on September 23, 2007 - by Jordan H
PHP Session Purging
I’ve been trying to make a login script that purges the sessions database so that users will only stay inactive for 1 hour until they have to log in again. All seems to be well, but then it just doesn’t work.
This is the code which I have on every page:
$time = date("ymdHis");
$cutoff = $time-1000;
$sql = "DELETE FROM adminsessions WHERE time<'$cutoff'";
mysql_query($sql) or die(mysql_error());
It should log the user out after 10 mins of inactivity. Doesn’t seem to be doing that at the moment. Anyone got any ideas?
This entry was posted on Sunday, September 23rd, 2007 at 2:11 pm and is filed under Coding. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Visit My Website
January 18, 2008
Permalink
Hi Jordan,
What field type is the ‘time’ field?
Try $sql = “DELETE FROM adminsessions WHERE time<$cutoff”; too (without the quotes around $cutoff)
Regards,
Charlie
Visit My Website
January 18, 2008
Permalink
I fixed it using that way ages ago.
But thanks for the call!
Visit My Website
January 18, 2008
Permalink
Thought it was a bit old to comment on, but I was a tad bored! (6)
Visit My Website
July 5, 2008
Permalink
Field type must be float, int or bigint for size operators like > and < to work, and also for ordering with ORDER BY to work.
–damo