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?
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:
$_COOKIEand$_SESSIONinstead of redirecting using a meta tag redirect with HTTP headers: