Forum Moderators: coopster
I'm in a 'back-end' project that requires the date/time capture of when an admin logs-in, and then logs-out. What I've already done is set up a session which (upon log-in) captures time(); and when the user clicks the log-off button, another session captures time() and both are fed into proper fields in the db. So far, no problem.
BUT... what if the admin (or someone else that happens to sit down at the person's computer) decides to go to another site before they hit the log-off button? Or, what if the person closes their browser (or the power goes out) before they initiate the log-off? What then?
I've troubled over this a bit and don't think theirs a solution to either scenario unless I implement some kind of javascript counter that updates the log-off db field every minute or so but I don't really like that solution.
Is there another way to tackle this? Is there any way to detect a person going off-site or closing down their browser?
Neophyte
So on each page load check something like -
if ($_SESSION['last_page_load']+300 > time()) { // last view longer than 5 min ago
[url=http://uk.php.net/manual/en/function.session-destroy.php]session_destroy[/url]()
$_SESSION = array();
// unset cookie
// kill session
}
else {
$_SESSION['last_page_load'] = time();
}