Forum Moderators: coopster
Following is a simplified sketch of a script i have.
<?php
/*
// some code here for testing/cleaning/veryfing POST/GET data
*/
$var = $_POST['var']; // example
$time = time()+(86400*30); // 30 days from now
$unique_var = md5(time()); // some unique identifier
if (!isset($_COOKIE['mycookie']))
{
// create cookie if it doens exist
setcookie("mycookie", $var, $time, '/');
}
if (isset($_COOKIE['myuniquevar']))
{
// delete old cookie
setcookie("myuniquevar", '', time()-7200, '/');
// create new one
setcookie("myuniquevar", $unique_var, time()+3600, '/');
}
echo "<pre>";
print_r($_COOKIE);
echo "</pre>";
?>
I have test the following code with Firefox Lice http headers and it seems to work fine (i can see the 2nd cookie being deleted and re-created.
Now the problems.
In Firefox, i need to refresh the page to see the two cookies values printed on screen (else i see only the first value, plus the cookie value from PHPSESSID
In IE no matter how many hours are passed, the 2nd cookie value stays the same (even if it is supposed to expire after 1 hour). I need to close the browser, cleanup the cookies and re-load the page for a new value for 2nd cookie
Am i doing something wrong?
The problem is that in IE the cookie isnt deleted untill the browser window is closed (i delete it, visit another page and then back to original page and the cookie is still there).
And in FF the 2nd cookie is created only after a page-refresh or a 2nd visit to the page
I will try the cashe clear method and i hope it will work.