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
Normally you would put such information in sessions.
$_SESSION['user'] = "A user name";
Then when you want to logout you do:
session_destroy();
Some more info on sessions here and a tutorial.