After the user successfully logs in, I store login = true in database. But how do I check if the user logged out by closing the browser without clicking the logout button? A
AFAIK there is no way for you to check when a person closes the browser window (or leaves you page to go to another) so you need to check activity as others suggested above.