mark110384 Posted June 20, 2008 Share Posted June 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/111107-solved-delete-expired-session/ Share on other sites More sharing options...
MadTechie Posted June 20, 2008 Share Posted June 20, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/111107-solved-delete-expired-session/#findComment-570193 Share on other sites More sharing options...
mark110384 Posted June 20, 2008 Author Share Posted June 20, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/111107-solved-delete-expired-session/#findComment-570227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.