Instant Cookie Deletion in PHP
In order for the
$_COOKIE array to change immediately when deleting a cookie,
you can use the clever technique we already know:
<?php
setcookie('test', '', time());
unset($_COOKIE['test']);
var_dump($_COOKIE['test']);
?>
Let's add a condition so as not to delete an already deleted cookie every time:
<?php
if (isset($_COOKIE['test'])) {
setcookie('test', '', time());
unset($_COOKIE['test']);
}
var_dump($_COOKIE['test']); // deleted
?>
Delete some cookie using the clever technique. Make sure it gets deleted immediately.