What's the reason for cookies mysteriously reappearing?

不想你离开。 提交于 2019-12-22 10:56:14

问题


I'm developing a web application using a cookie to store session information. I've manually deleted the session cookies because I'm working on another part of the code where I don't want a login session. However, after a couple reloads of the page, the session cookie mysteriously reappears, including an earlier cookie that I had only set once for testing purposes, then deleted and never used again.

I keep manually deleting the cookies in question, but still, when I reload the page after a while, the cookies are back. I've double-checked my code and I am positive I'm not setting those cookies anywhere. My code is all in one file at the moment, and I'm not including anything, so there's no possibility that I'm overlooking something.

My code is in PHP and used the setcookie() call when I initially created those cookies.

I've not set an expiry date on the cookies. Using Safari 4 Beta and the GlimmerBlocker proxy.

What's the explanation for this weird behaviour?


回答1:


There are known problems with certain browsers cookie handling.

See the following paper: iSEC Cleaning Up After Cookies

Also see this discussion on Apple.com regarding the case of the reappearing cookie.




回答2:


Try this, it should remove all of your session cookies:

    session_start();
    // Unset all of the session variables.
    $_SESSION = array();
    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (isset($_COOKIE[session_name()])) {
        setcookie(session_name(), '', time()-42000, '/');
    }       
    // Finally, destroy the session.
    session_destroy();



回答3:


What version of the OS are you using? What other apps are you using at the same time? These issues are generally due to apps stomping on the cookie storage file (~/Library/Cookies/Cookies.plist) one after another.



来源:https://stackoverflow.com/questions/714024/whats-the-reason-for-cookies-mysteriously-reappearing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!