I am creating a cooking in htaccess with a RewriteRule. In my testing I simply cannot get this cookie to go away. Here is how I am creating the cookie, which I was helped with in this thread:
[L,CO=redirect_indicator:yes:.www.example.com,R=301]
So the cookie has the default expiration time which should be for just the duration of the browsing session. I am trying to destroy it at the end of my script and I am just getting confusing results.
So, I will do this at the top of my script to see the cookie for testing purposes:
var_dump($_COOKIE['redirect_indicator']);
Then at the end of my script I run the following (with help from another stack thread here) I have tried much simpler destroy scripts than this as well but none seem to do the trick:
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}
Now after that code section I also run this again:
var_dump($_COOKIE['redirect_indicator']);
and infact the cookie is not there! Which is great, but just as soon as I run the script again on a page that should not generate the cookie, the cookie still shows up during my first var_dump.
Is there anyway to get rid of this cookie or will I always be at the mercy of what the browser has in store. It indeed goes away when I restart the browser, but I need this thing to go away after the script has executed.