gerkintrigg Posted August 25, 2007 Share Posted August 25, 2007 Hi all... I have searched but can't find a way to destroy a cookie easily using PHP. I want to do it so that all session and cookie info is removed when the user logs out. I have worked most of it out, but removing the cookies is causing problems. Please help. Ta, Quote Link to comment https://forums.phpfreaks.com/topic/66650-destroying-cookie/ Share on other sites More sharing options...
Jessica Posted August 25, 2007 Share Posted August 25, 2007 http://us.php.net/setcookie Look at: Example 1588. setcookie() delete example http://us.php.net/manual/en/features.cookies.php Quote Link to comment https://forums.phpfreaks.com/topic/66650-destroying-cookie/#findComment-333920 Share on other sites More sharing options...
gerkintrigg Posted August 26, 2007 Author Share Posted August 26, 2007 Hi... Thanks for the info, but I have tried that, and it doesn't seem to work (I dunno why). I'm using this code: setcookie ("username", "", time() - 3600); setcookie ("password", "", time() - 3600); I know I'm naming the cookie correctly, but whenever I go to http://www.nextdaygraphics.com homepage, it logs me in automatically anyway. I just want it to delete the cookie when i log out. Any suggestions are very welcome. Quote Link to comment https://forums.phpfreaks.com/topic/66650-destroying-cookie/#findComment-334436 Share on other sites More sharing options...
Fadion Posted August 27, 2007 Share Posted August 27, 2007 I found this on the user comments at php.net: Here is problem I ran into during a recent bout with IE7 and cookies. IE will not delete a cookie value if the time is set to the past. It will hold the value no matter how far in the past you set the "expire" value. IE7 is the only browser I have had problems with - so here is the solution I came up with. <?PHP //check to see how to set the cookie $Browsertype = $_SERVER['HTTP_USER_AGENT']; $Parts = explode(" ",$Browsertype); $MSIE = array_search("MSIE",$Parts); if($MSIE) { setcookie("name", "", time()+20000); } else { setcookie("name", "", time()-20000, "/", ".domain.com" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66650-destroying-cookie/#findComment-334831 Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 If you're using Firefox, someone has also posted comments about deleting cookies for it. The above example does not look like it will work for deleting a cookie for IE7...it looks like it just extends it, or deletes the value for it. Also, make sure you're using the full domain and all of the parameters. If you set it for domain.com, then delete it for www.domain.com and then you're on domain.com again, the cookie will show. It might not even be the cookie, it might be your code. We'd need to SEE the code to tell. Quote Link to comment https://forums.phpfreaks.com/topic/66650-destroying-cookie/#findComment-334837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.