Reputation: 889
So I have this code on my index.php:
<?php if(isset($_POST['cookie'])) { setcookie("RememberMe", "Yes", time()+1209600); } ?>
If the user has checked the remember me box then it will set a cookie with the name RememberMe for 2 weeks. This part works fine.
Now the issue I'm having is deleting this cookie when they press logout.
On pressing logout, they get redirected to logout.php which has the following code:
<?php include_once('config.php');
include_once('functions.php');
unset($_COOKIE['RememberMe']);
setcookie("RememberMe", "", time()-3600);
$_SESSION = array(); session_destroy();
?>
<meta http-equiv="refresh" content="0;../index.php">
but for some strange reason that won't delete the cookie? Any ideas as to why?
Upvotes: 2
Views: 427
Reputation: 5399
Cookie cancelations can sometimes require the same time value as they were set.
setcookie("RememberMe", "", time()-1209600);
Upvotes: 0
Reputation: 9480
You may want to check if the path the cookie is set at is correct. By default PHP sets the cookie path to the directory it's set in and it will not be available (nor possible to delete) from different locations.
Few more tips:
$_COOKIE
and $_SESSION
instead of redirecting using a meta tag redirect with HTTP headers:
header('Location: /index.php'); // or whatever is the path you want to redirect to
Upvotes: 2
Reputation: 115
Not the cleanest but Check the time zone is correct Ensure you are nuking the correct cookie( case sensitive ) Failing all of they over writing the cookie will nuke it anyway So...
Setcookie('mycookie') // nukes the cookie with a blank entry
Upvotes: 0