I’ve got a website, let’s call it www.example.com In that website there are two pages. One creates a cookie like this:
setcookie('daCookie', 'boo', 2000000000, '/', '', false, true);
And the other one tries to delete it like this:
setcookie('daCookie', '', 1, '/', 'www.example.com', false, true);
setcookie('daCookie', '', 1, '/', '.www.example.com', false, true);
Now, I know that the first script was called in context of www.example.com. If I use the browser’s (Google Chrome in this case) developer tools, I can see that the cookie’s domain is www.example.com. However the second call does not delete it. If I change it to the empty domain:
setcookie('daCookie', '', 1, '/', '', false, true);
Then it works. But I’d really like to specify the domain explicitly. Why doesn’t it work?
I believe in the second call (explicitly passing the domain name), browsers may prefix the value with a dot (.) since its a domain. Which is why that call does not delete the cookies that was set previously (not passing the $domain param.)