Find out if a session with a particular id has expired

后端 未结 3 438
独厮守ぢ
独厮守ぢ 2021-01-28 09:13

I am creating an upload feature that stores a user uploaded file on the server with the user\'s session-id as its name. Now, I want to keep this file on the server only till tha

3条回答
  •  悲哀的现实
    2021-01-28 09:28

    You can't just rely on session.gc_maxlifetime because after this time the session is marked as garbage and the garbage collector starts only with a probability of 1% by default ( session.gc_probability).

    The better approach IMHO is to handle yourserlf the expired data.

    You can for instance start the time and save it into a session variable:

    
    

    Later..via cron you can do something like this:

     $timeout){//Session is expired
      //delete file
      session_destroy();
    }else if (!isset($_SESSION['last_seen')){ //already garbaged
      //delete  file
      session_destroy();
    }
    ?>
    

    Not tested...just an idea

提交回复
热议问题