Hey. I have a function that's run every time a user visits a page, to check that they are logged in. Here is the code:
function pageProtect($guestonly = false)
{
if ($guestonly == false && !User::authenticated()) {
$alerts = array();
$alerts[] = array('type' => 'warning', 'message' => "You must sign in to view this page", 'dismissable' => false);
//Put it in the session variable
$_SESSION['alerts'] = $alerts;
header('Location: /user/signin');
}elseif ($guestonly == true && User::authenticated()) {
header('Location: /dashboard');
}
}
When I visit /dashboard, it successfully redirects to /user/signin. However, there is nothing in the SESSION. No errors appear in the logs. The session has already been started, and if I try to start it again it produces an error. I also have another function that reads session data, and that works fine. The session set code is running, but why isn't it setting? This code is identical to code on another page where it does work.
Any help would be great!