Blog

25 Jul
2013

php Elephant Icon Logo

Reset cookies expiry date is not working in php


While recently working on a website I was trying to unset a cookie by resetting its expiry date back an hour using setcookie. But for some reason it would not work. Here is the code I was trying...

<?php
setcookie('CookieName', '', time()-3600);
unset($_COOKIE['CookieName']);
?>

Eventually I got it working by simply adding , '/'. So if you are having the same problem... I hope this helps.

<?php
setcookie('CookieName', '', time()-3600, '/'); // ADDED HERE //
unset($_COOKIE['CookieName']);
?>
Tagged: < cookie | expiry date | fix | php | reset | setcookie | unset >
Posted in: < PHP and HTML and CSS >
me@grafxflow avatar

me@grafxflow


I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Visitors also viewed these posts


Add comment

Add comment