0

I am making a website with a user system and a login system. I am using simple PHP scripts with mysqli functions to manage the users. I can log in and I can log out.

My only problem seems to be that if a user closes the tab/browser, the column in the database describing if the user is logged in or not (I need that to prevent double logins because we have multiple GUIs apart from the website) is not getting reset to 0 (meaning not logged in). I have a logout button that send me to the logout script in which I do reset the userSignedIn column, but i cannot find a solution to how to react to the tab closing.

Browser: I am using Google Chrome but would like it to work on most modern browsers. PHP: Version 7.3.12

I have already seen this question and it's answers: Detect browser or tab closing

I have tried this solution, but apparently it is an outdated one or I am just not getting it right. I also heard it just works if there is only one tab open. https://stackoverflow.com/a/5593734/12614408

Is there a way in 2020 to have an eventlistener that listens to tab/browser closing and not at refreshes or page unloads?

McFLoDuR
  • 1
  • 2
  • Maybe this will help you: https://www.geeksforgeeks.org/how-to-detect-browser-or-tab-closing-in-javascript/. – Leon Kunštek Jan 01 '20 at 17:18
  • @LeonKunštek thanks, but this also triggers when user is navigating to another page. I want it to react to purely closing action. Because maybe he is navigating to another page on my website and still wants to stay logged in. – McFLoDuR Jan 01 '20 at 17:41

0 Answers0