But I would really like to be able to detect when they log out, not when they re-visit the website, since a hacker could cheat this method by inserting some code to set the session variable before this is checked or comment out this code. However, people are much less likely to hack the website in a way that hurts themselves upon closing the website.
Just in general, seems like running code upon the ‘beforeunload’ event would be really nice.
I’m not sure what you’re asking. How to detect when the user leaves the website or how detect when the user actively logs out or maybe something else?.
Although you can possibly set that up on your desktop site with onMouseIn on a transparent element that is situated near to the the browser close button, so a lightbox, strip or box etc could be set to be shown with the option for the user to logout before closing the website.
However, it would only work if they used the browser ‘x’ for closing and not the browsers own file-close option and would not work on tablet or mobile devices as you can’t use onMouse with them.