Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php, how to detect is a session ID is dead or alive? [duplicate]

Tags:

php

session

Possible Duplicate:
How do I expire a PHP session after 30 minutes?

How to detect is a session ID is dead or alive? Lets suppose somebody logged in - a new session is created and I save the session ID. If he logins from another browser, I can determine that he is logged in twice. But how to detect if he logs out?

like image 642
John Smith Avatar asked Jun 19 '12 15:06

John Smith


1 Answers

What you would need to do is when he logs in to his account on a new browser, find the old sessionID associated with his account and expire it. When he clicks a logout button, you can then retire that sessionID.

EDIT:

Sorry I read your question wrong. What you want to do is set a session timeout so if the timeout is reached, you assume the session is dead and expire it. On each page request, you will renew the expiration so that it is live. If they login from another browser, you can assume the session in the old browser is old, and expire it right off the bat or let it expire with the timeout.

You can then check session timeouts on page load, or run a cron script that will run through the session database and expire all old sessions.

like image 114
Bot Avatar answered Oct 04 '22 23:10

Bot