Jump to content

[SOLVED] Delete expired session


mark110384

Recommended Posts

Hi, I'm currently trying to write a function that will check a mysql table and bring back data regarding the createdate of a record referenced by a session_id(), I would then have to determine if the session has expired and then delete the session from the mysql database. I'm having a problem in writing the code to check the session as shown bellow, if anyone has any suggestion or could point me in the right direction I would be greatful.

 

$sqlfindsessiontime = "SELECT createdate FROM cart_items WHERE session = '$session'";

 

$resultfind = mysql_query($sqlfindsessiontime);

 

while($myrow = mysql_fetch_array($resultfind))

{

$finddate = $myrow['createdate'];

 

if ($finddate <= 3600 //The problem is here! I don't know what I would put.

Link to comment
https://forums.phpfreaks.com/topic/111107-solved-delete-expired-session/
Share on other sites

replace 3600 with time()-ini_get("session.gc_maxlifetime")

the problem is if session.gc_maxlifetime is set to 0 then it means the life time will be until the browser closes.. but this is set from your server..

 

EDIT: the default is 1440 (24 minutes)

Thank s MacTechie but I found the souloution the mysql, as follows, it essentially deletes other users expired sessions and theoretically other users will then delete my expired sessions.

 

        $session = session_id();

 

$sql = "UPDATE cart_items SET createdate = now() WHERE session = '$session'";

 

$result = mysql_query($sql);

 

$sqldelete = "DELETE FROM cart_items WHERE (TIME_TO_SEC(now()) - TIME_TO_SEC(createdate)) >= 3600";

 

$sqldelete = mysql_query($sqldelete);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.