Saving the time the user is logged on
Asked Answered
B

2

6

In the application I am developing I have to store the time some particular users remain logged into the application, unfortunately, in web applications, there are several ways the user can log off.

  1. User clicks log off.
  2. User session expires.
  3. User closes the window.
  4. User types another site URL in the address bar.

The first one is quite easy because the application gets control of the logging off process. But in the other ones, it gets tricky.

What would you do to solve this problem?

Browband answered 14/10, 2008 at 22:12 Comment(0)
A
8

On each page view, update your count. If they log out, then you've got an accurate measure. If they navigate away, or any other method, then the most that you're out is the length of time they were on one page.

If it were really really important to have an accurate measure, then perhaps an AJAX "heartbeat" every minute, but that's most likely overkill.

Aundrea answered 14/10, 2008 at 22:14 Comment(1)
Just like stackoverflow's "heartbeat" :)Grieve
G
1

Well for #3 and #4 you can attach something to the window.onunload event that gets you the time for calcuations, but be careful that your code is fast enough that the page doesn't completely unload before your AJAX request can be sent.

As far as #2 goes, the "heartbeat" suggested by nickf is probably the best solution there.

Grieve answered 14/10, 2008 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.