Is it possible to remove cookie that was set on front via JS with PHP?
I'm doing this:
*FRONT (JS):
if ($.cookie('myCookie'))
{
console.log('Cookie.. :( ');
}
else
{
console.log('Yaay! No cookie!');
$.cookie('myCookie', '123');
}
BACK (PHP):
if (isset($_REQUEST['removeCookie']))
{
setcookie("myCookie", "", time()-3600);
unset($_COOKIE['myCookie']);
}
Result:
Seems like it's a mistery
You can't force the browser to delete the cookie file. You can, however, delete the contents of the cookie and expire it. Which is exactly what you're doing with your code above. I would probably tweak it slightly:
setcookie('myCookie', '', 1, '/'); // no need to calculate one hour ago.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With