I'm trying to make a simple members area. It was all working fine until I wanted to make a button in my navbar different if the user was logged in. I found that from the navbar include I couldn't access the cookie because navbar.php was in a different directory. So I searched Google and I found that I had to set the cookie's path to "/". After doing this my navbar worked flawlessly. I later found that my logout page had stopped working. After a lot of frustration I am unable to figure it out so I was wondering if I could get some help.
Here is my set cookie code from the login
$_POST['userMemberNumber'] = stripslashes($_POST['userMemberNumber']);
$hour = time() + 21600;
setcookie("ID_wragc", $_POST['userMemberNumber'], $hour, "/", ".wallingfordrodandgunclub.org");
setcookie("Key_wragc", $postPassword2, $hour, "/", ".wallingfordrodandgunclub.org");
header("Location: membersindex.php");
and here is the code from my logout page
$past = time() - 3600;
setcookie("ID_wragc", "", $past, "", "");
setcookie("Key_wragc", "", $past, "", "");
header("Location: ../index.php");
The cookie gets created just fine, but I can't remove it on logout.
Your expiry time needs to be >= your set time (21600) and also need the same dir and folder.
$past = time() - 21600;
setcookie("ID_wragc", "", $past, "/", ".wallingfordrodandgunclub.org");
setcookie("Key_wragc", "", $past, "/", ".wallingfordrodandgunclub.org");
header("Location: ../index.php");