When a user first logs in I add a $_SESSION['login'] = true;.
In another function I'm checking the login session variable to make sure a user has logged in and not just navigated to that page. Like this.
if ((!isset($_SESSION['login']) && $_SESSION['login'] != '') || (empty($_SESSION))) {
session_register_shutdown();
header("Location: login.php");
exit; // stop further executing, very important
}
So if the login session variable isn't set I redirect to the login page. It works but I get an Undefined index: login error when it redirects. Is there a way to fix this?