themistral Posted December 7, 2010 Share Posted December 7, 2010 Hi guys, I am having a sticky problem with Cookies. Basically, I've had to change the settings of my CMS which has resulted in me now having the same cookie names for the cookie domains .domain.com and www.domain.com. I know I can just clear my cookies and the problem will be sorted, but it's not feasible for me to expect users of my site to clear their cookies. So my question is this. How can I delete the cookies created using www.domain.com with PHP? Everytime I set the expiry date of the cookies, it only applies it to those on .domain.com. Any help would be gratefully appreciated!! Link to comment https://forums.phpfreaks.com/topic/220932-cookies/ Share on other sites More sharing options...
AbraCadaver Posted December 7, 2010 Share Posted December 7, 2010 You'll need to be more specific, but if you want to control what domains the cookies are used on, use session_set_cookie_params() or setcookie() to specify. If you want example.com and www.example.com to be different then don't use (notice the . ) .example.com as this applies to all subdomains of example.com. Link to comment https://forums.phpfreaks.com/topic/220932-cookies/#findComment-1144018 Share on other sites More sharing options...
themistral Posted December 7, 2010 Author Share Posted December 7, 2010 Hi, The problem is that I have $_COOKIE[foobar] set in .domain.com but also have $_COOKIE[foobar] set in www.domain.com]. The one in .domain.com is correct, but I don't seem to be able to access the cookie set to www.domain.com. Link to comment https://forums.phpfreaks.com/topic/220932-cookies/#findComment-1144023 Share on other sites More sharing options...
themistral Posted December 9, 2010 Author Share Posted December 9, 2010 Please guys, Can this even be done? Everytime I set the cookies to expire in the past, it only clears the cookies from .domain.com - the cookies for www.domain.com are left. $expiry = time()-10000; foreach ($_COOKIE as $key => $value) { setcookie($key, '', $expiry, '/', 'www.domain.com'); } Link to comment https://forums.phpfreaks.com/topic/220932-cookies/#findComment-1144859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.