PHP login / logout question

I’m thinking of introducing a small tracking system that will track login time / logout time, and also track who is currently logged in. All this makes sense to me, except for tracking when a user logs out. It is easy enough when the user clicks the "Logout" button, which calls a function that can update the database with the logout time, but what if the user just logs out of the browser. How to create a function that will handle this event, and I assume that there are any other situations that I did not think of when the user exits the php application in an unofficial way. In addition, any links to online tutorials on this subject would be highly appreciated.

+3
source share
3 answers

The simplest solution is, perhaps, simply marking the user as “active” every time he performs an action on your site (that is, every time a page is created on the server) - you already know how to do it.

And if the user has been marked as “active” for a long time (i.e. more than 5 minutes, for example, maybe more depending on the type of content that you have on your site), you might think that he is not more active - maybe not even on your site, actually.

Of course, you have a couple of minutes of delay before you discover the user is no more ...


- Ajax, : , , ...

, /, , ( , firefox, /!)

+12

Javascript PHP ( AJAX) , , , 30 .

+3

, .

: AJAX - - /?

-, before_unload.

, , , .

, , . , , 5 . .

, , , AJAX-ly (, 30 ) , .

+2

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


All Articles