开发者

Check if a PHP SessionID is in use?

at one of my project, i store a temporary data in database with a s开发者_开发知识库essionId, and i've to delete them if its sessionId is not in use, is there a simple way to check if session id is in use?


Store a last accessed timestamp, and delete those rows whose time is X minutes earlier than the current time.


You can name your session with session_name ([ string $name ] ),

example: session_name('myname'),

and then just check if there is a session id for that name with session_id ([ string $id ] ),

example:

if(session_id('myname') != "")
       echo session_id('myname');
         else
      //your code here


is there a simple way to check if session id is in use?

If you are using the default session handler then checking if the session file is present and has been modified since time()-session_cache_expire().

However a much better solution would be to use a database-bound session handler. This is much more flexible when trying to look at session data from outside the session, you could just do a simple join to find the matching data, but the right way to solve the problem is to implement the session management code within the session handler (i.e. delete the data when the session is deleted)!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜