PHP Session expire event

前端 未结 3 431
暖寄归人
暖寄归人 2020-12-11 10:10

I am trying to make some changes to an opensource project. I want to keep track of when users log in and log out. Right now I change their login status in db when they logi

3条回答
  •  爱一瞬间的悲伤
    2020-12-11 10:40

    I presume you're using standard PHP file-based sessions. If that's the case, then PHP will do its own garbage collection of stale sessions based on the session.gc_* configuration parameters in php.ini. You can override those to disable the garbage collector completely, then roll your own GC script.

    You could either check the timestamps on the files (quick and easy to do in a loop with stat()) to find 'old' sessions, or parse the data in each file to check for a variable that lists the last-access time. Either way, the session files are merely the output of serialize($_SESSION) and can be trivially re-loaded into another PHP instance.

提交回复
热议问题