Skip to content
Advertisement

Can’t delete php set cookie

I’ve set a cookie through this call in php

JavaScript

I have tried unsetting it this way

JavaScript

and it still won’t unset the cookie value in $_COOKIE[‘alert_msg’].

I have tried in both Firefox and Chrome

Code sample:

JavaScript

Advertisement

Answer

Checkout the cookie path.

Since you are not passing the path parameter to the setcookie function, in this case the cookie will be set for the current directory only and can be used and can be unset from that directory only.

Possible solution is to pass the path value as /. So that cookie can be used and unset from any part of application.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement