Problems deleting cookies, won't unset

后端 未结 18 739
死守一世寂寞
死守一世寂寞 2020-12-09 15:33

I\'ve tried searching the php manual and internet on how to delete cookies and I\'ve tried it the exact same way they all say:

setcookie(\"name\", \'\', 1);
         


        
18条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 16:35

    I'm surprised no one has mentioned it (or maybe I missed it), but domain is important too! If you are on sub-domain.example.com, and the cookie is from .example.com, then you need to explicitly set the domain parameter, otherwise it will assume the current domain and it won't work.

    setcookie('cookiename', FALSE, -1, '/', '.example.com');
    

    Sub-domains value will not clear cookies from parent domain.

提交回复
热议问题