Forum Moderators: coopster

Message Too Old, No Replies

cookie issues

unexplaing behaviour?

         

omoutop

3:11 pm on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello all.

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?

andrewsmd

4:47 pm on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try clearstatcache(); to clear some things
to reload the page put either the meta refresh tag in with a specified time or a header("Location: self.php"); where self.php is your address. To close the browser, I don't know if you can do that with php.
to delete your old cookie try setcookie("myuniquevar");

omoutop

7:12 am on Nov 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you got me wrong
- i dont want to close the browser
- i dont want to reresh the page
- i must not refresh the page for the cookie to work
- i know how to delete the cookie (i have mentioned that i can see the headers for deleting it and re-creating it).

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.