Saving user login time

In the application that I am developing, I have to store the time that some specific users remain in the application, unfortunately, in web applications there are several ways to exit the system.

1.- The user will log out. 2.- Duration of the user session. 3.- The user closes the window. 4.- The user enters the URL of another address in the address bar.

The first one is pretty simple, as the application takes control of the logout process. But in others it becomes difficult.

What would you do to solve this problem?

+4
source share
2 answers

On each page view, refresh your score. If they log out, you will get the exact measure. If they move or some other method, then the most that you left is the time that they were on one page.

If it were really important to have an accurate measure, then perhaps AJAX "heartbeat" every minute, but this is likely to be unnecessary.

+7
source

Good for # 3 and # 4, you can attach something to the window.onunload event, which gives you time to compute, but be careful that your code is fast enough so that the page is not completely unloaded before your AJAX request can to go.

As for No. 2, the "heartbeat" proposed by nickf is probably the best solution.

+1
source

Source: https://habr.com/ru/post/1277751/


All Articles