I use the following in PHP to delete a cookie:
setcookie("cart", "", time()-3600, "/", ".site.net");
Which works as expected, when I link through to the following page the cookie is not found by PHP and I can confirm it has been deleted using the web inspector in Safari.
However the cookie is still being read on the second page by Javascript as is it was never deleted. I read the cookie in Javascript with:
var result = document.cookie.match(new RegExp(name + '=([^;]+)'));
Even if I keep reloading the page Javascript loads the cookie (and PHP does not). If I shift reload Javascript stops reading the cookie, so evidently the cookie is being cached and read.
I don't want to turn off caching for the whole page using HTML tags, so is there a way to stop caching of cookies alone, or to stop Javascript using the cache on this page?
If I delete the cookie via Javascript there is no issue.