Forum Moderators: coopster

Message Too Old, No Replies

Capturing a users "log-out" time when the go "off-site"

         

neophyte

11:04 am on Apr 11, 2008 (gmt 0)

10+ Year Member



Hello All -

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

henry0

11:16 am on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hmmm, interesting quest :)

Couldn't you grab from one of those repository sites
A “Who’s online script”…

See where I am going with this…

coopster

1:01 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The JS updater would be running back and forth to the server too often if you ask me. If the person does not log out by using the proper procedure you can always use the garbage collection routine of your session to set the logout time and also indicate that the logout was improper.

PHP_Chimp

6:01 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you limiting the time that a session is active for? As if you are then assuming you have a 5 min time limit on the session you could use that to get a non-exact log off time.

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();
}

This would not give you an exact log off time, but gives a window of time in which they exited your system.
I dont know if that would be accurate enough for what you want.