title: PHP Count Logged-In Users
body: <p>I'm having trouble figuring out how I can count the number of logged-in users in my application.</p>
  
  <p><strong>What I have:</strong> When a user logs in, they get a session (which is used when the user wants to visit a protected page) and the IsLoggedIn column for the user in the users table is set to 1 to indicate that the user is logged in. When the user logs out, the value is set back to 0. Counting the number of 1s in the users table makes it easy to return the number of users logged-in. But...</p>
  
  <p><strong>The Problem:</strong> If the user closes the browser without logging out, the value in the database stays 1, indicating that the user is still logged in even though their session has ended when they closed the browser.</p>
  
  <p><strong>Question:</strong> Could some one suggest a proper way of doing this?</p>