as advised use sessions , you can use sessions with or without cookies dependiing on your preferences. Just go to google.com and search for tutorials on login
Once you are using sessions then you can use something similar to:
function isMember() {
//global $SESSION;
return ((isset($SESSION["USERNAME"])) or ($SESSION["USERNAME"] == "guest") or ($SESSION['USERID'] == 0));
}
then just call the function isMember at the top of any file e.g.
if(!(isMember()))
{
header('Location: home.php?error=badlogin');
}
If you decide to stick your db instead of sessions. Then :
Instead of
return ((isset($SESSION["USERNAME"])) or ($SESSION["USERNAME"] == "guest") or ($_SESSION['USERID'] == 0));
use a database connection to find out what the value of 'logged' is and return the value off logged.
Note : MAKE SURE YOU STORE AT WHAT TIME YOUR USER LAST LOGGED IN AND EXPIRE IT AFTER SOMETIME YOU DONT WANT YOUR USER TO BE LOGGED IN FOREVER