Delete PHP Cookie?

前端 未结 3 1264
醉梦人生
醉梦人生 2020-12-20 18:04

I currently have a cookie set as follows:

setcookie(\"username\",$username,time()+3600*24*5);

How would I go about clearing the value of th

相关标签:
3条回答
  • 2020-12-20 18:34

    Setting its expiration to some time in the past should clear it:

    setcookie("username",$username,time()-10);
    

    If you're using PHP sessions to manage users, you'll probably also want to session_destroy()

    0 讨论(0)
  • 2020-12-20 18:35

    Be sure that you delete the cookie with the same domain name and path with which you set it. Cookies for example.com and www.example.com will be treated as two different cookies. Similarly, cookies set from example.com and example.com/Support will have different paths. A good practice is to use .example.com as the domain and '/' as the path for username type cookies so that they can be shared across your subdomains too.

    To debug this, you can use the FireCookie plugin of Firefox which'll show all this information.

    0 讨论(0)
  • 2020-12-20 18:42

    You really should not store your users password in a cookie, especially if you are not using HTTPS! The password will be sent in plaintext over the network for every requests! Also, never send back a user his password, this is nerver a good idea.

    0 讨论(0)
提交回复
热议问题