Home > Blockchain >  Client have doubled cookie name and browser send to server the wrong one
Client have doubled cookie name and browser send to server the wrong one

Time:09-09

Website mydomain.com with php server worked fine with below cookie settings:

domain=null
secure=false
path=/
http-only=true
same-site=null

Once i changed the cookie domain on ".mydomain.com" clients started receiving cookies with ".mydomain.com" domain, but the old ones with "mydomain.com" domain were not removed. After that, each request to the server contains both old and new cookies with different values. The order of cookies with same name in the header is unpredictable. The server puts in the $_COOKIE var only those cookies that come first in order.

The problem is that the correct cookie is the one that comes after another with same name in the cookie header. How can I remove the old cookie with "mydomain.com" domain ? Or how can I get correct cookie from the client?

CodePudding user response:

So, I just redefine cookies i want to remove with expiry option in the past like this:

setcookie('cookieName', '', 1, '/', 'mydomain.com');

Using this function. And 'path' cookie option is also important to specify, because the cookie with different path - is different cookie.

Thanks to @cbroe for help.

  • Related