Jump to content

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.