I'd like to know when a user closes the browser, and before closing, write in database that user's session is inactive? Or, how can I make some external program that monitors whether the person is with the browser open, and when there is no response, considers that the browser is closed? I have an application that allows for up to three users logged in with the same account. By the time the user logs in, keep in the database user's id, time and date when logged in, as well as an 'active' flag indicating that it is logged. If the person tries to login, I can check in database that there are already three authentication for that user and I don't allow the fourth. If user is out, I record this information in database and allow him to log in again, up to three logins. I know when the user is loged out, but I don't know when it closes the browser.
Asked
Active
Viewed 54 times
-2
-
1This question's been asked before. Have you went through Google first? – Funk Forty Niner Jun 24 '15 at 19:24
-
Besides this is not done with PHP. PHP is executed server-side, what you need is probably javascript, which is executed client-side. – Brian Jun 24 '15 at 19:26
1 Answers
1
No there is no way accurate failsafe way. I recommend not basing your logic on this to maintain state, imagine the case of a power outage you'll never be able figure out what happened so your logic will always be inaccurate. Instead, use a server-side timeout logic.

Wadih M.
- 12,810
- 7
- 47
- 57
-
1You mean, as per [what this page talks about?](http://stackoverflow.com/questions/10849561/detecting-browser-exit-in-php) – Funk Forty Niner Jun 24 '15 at 19:29