I already had this problem and found some tips, but no effect, like Jquery $(window).unload(function()
, but none of them worked.
The best thing I saw that you could do was:
1 - you record in the database the date and time that the user logged in to each login;
2- Create a function that every page visited updates every x minutes, this login time; (you can call this function in __construct
of each controller)
3 - create an event in your database, which runs a select every "y" minute checking if the date recorded in the database is less than 5 minutes for example, according to time you set to last his session.
( remark ) If it is a site with lots of concurrent access, it probably will not be a good idea, maybe it needs to be a dedicated server, since the bank event runs in infinite loop, so it works. >
Because if the user accidentally closes the page and wants to get back to where he was, he will be able to do so without having to sign in again due to the active session.
And if it happens to actually close the page without logging off then you set it to 1 minute after the session time expires, to be the maximum time difference from the current server time, with what is in the database.
Example, session set to 10 minutes, you set the time to check in the select between 11 or 12 minutes.
I hope I have helped. Good luck.