Tutorial :Multiple cookies with same name



Question:

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?


Solution:1

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


Solution:2

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.


Solution:3

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »