views:

461

answers:

3

I just figured out that I have a problem in IE while working with one of my pages. I set cookie with:

setcookie('page', '12345', '2000000', '/');

And if I login I reset the cookie calling that function again. In firefox everything works fine cause the old cookie is deleted but in IE both cookies stay? How can this happen? Isn't that illegal?

now I fixed that with:

setcookie('page', '', time() - 3600, '/');
setcookie('page', '1234', '2000000', '/');

Is this ok solution or am I missing something?

+3  A: 

According to the documentation, that is the correct way to remove a cookie.

Jordan Ryan Moore
Yes, but $_COOKIE['page'] = '1234' will not change client cookie value, only server value.
dfilkovi
A: 

Just a hunch, but it seems that the expires value is quite low for a timestamp, so the cookies probably expire immediately (ie. on session end). Maybe something like that is confusing IE by allowing multiple cookies?

You should probably use time() instead to set expiry, for instance:

setcookie('page', '12345', time() + 3600, '/');

Btw, your solution seems fine to me.

Sune Rievers
A: 

I am experiencing a similar problem.

I reload my page multiple times, using session_start() every time it loads. JavaScript sets cookies that I use in PHP. When the client is Internet Explorer, $_ENV["HTTP_COOKIE"] contains multiple entries for each cookie. This does not happen with Firefox.

As near as I can figure so far, when executing code at a domain named x.y.z, Internet Explorer sends the cookies for x.y.z followed by the cookies for y.z. PHP then puts both sets of cookies into $_ENV["HTTP_COOKIE"].

Perhaps this may be considered a PHP bug, perhaps not. IMHO, this is an Internet Explorer bug. I post it here in the hope that it may help you resolve your problem.

      ... Warren Gaebel, B.A., B.C.S.
Warren Gaebel