-2

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.

1 Answers1

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