I am trying to create a page that logs out the users on my website, but when I try to reinitialize the session, my page keeps saying Warning: session_regenerate_id(): Cannot regenerate session id - session is not active
. The code that starts the session:
try {
if (!isset($_SESSION) or session_id() == "") {
session_start();
if (!isset($_COOKIE['auth']) or $_COOKIE['auth'] != 'NO') {
$_COOKIE['auth'] = 'NO';
}
}
} catch (Error $e) {
echo "Caught Error: $e";
}
The logout page code:
try {
unset($_SESSION);
session_regenerate_id(true);
} catch (Error $e) {
echo "Caught Error: $e";
}
There are not session_destroy()
s or anything like that anywhere else on my website (as mentioned here), and I can see that the PHPSESSID cookie is set and after clearing the cookies gets set again after a page refresh.