Reputation: 23276
I am trying to unset the cookies, I had earlier set as:
setcookie(session_name(),$sessionID,time() + 30*24*3600,'/');
setcookie('UserID',$result[0]['UserID'],time() + 30*24*3600,'/');
setcookie('UType',$result[0]['UType'],time() + 30*24*3600,'/');
setcookie('Username',$Username,time() + 30*24*3600,'/');
Logout File:
function unsetCookie() {
foreach($_COOKIE as $key => $value) {
// $_COOKIE[$key] contains the cookie name as expected
setcookie($_COOKIE[$key],'',time()-(40*24*3600),'/');
}
}
unsetCookie();
session_start();
session_destroy();
header('Location: '.$loginPage);
exit();
But after the redirect in the logout file, cookies
are still not deleted. What could be the reason for this?
Upvotes: 1
Views: 44
Reputation: 6661
Set the value to "" and the expiry date to yesterday (or any date in the past)
Try this code like that :-
setcookie("UserID", "", time()-(40*24*3600));
setcookie("UType", "", time()-(40*24*3600));
setcookie("Username", "", time()-(40*24*3600));
Upvotes: 1
Reputation: 91742
$_COOKIE[$key]
contains the value of your cookie, not the key as that is $key
.
So you would need:
setcookie($key,'',time()-(40*24*3600),'/');
Upvotes: 4