title: Updating MySQL database when user closes browser
body: <p>I'm developing a web application for a research company and one of the requirements is that a user can only log in on one device at a time. </p>
  
  <p>So I developed a pretty basic system where when you log in some PHP updates a user's row in the database from 0 to 1 and when you click the logout button it updates that row again from 1 to 0. </p>
  
  <p>The only problem is if the user does not use the logout button and simply closes the browser, it will end the session and log them out but their row in the databse will not be updated. </p>
  
  <p>Is there a way to update the database on browser close?</p>