SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unsetting cookies

    How does one unset cookies? Does that go with the unset() function as well?

  2. #2
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kon-Tiki View Post
    How does one unset cookies? Does that go with the unset() function as well?
    you can try with
    unset($_COOKIE["mycookie"]);

    it should work

  3. #3
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shouldn't. $_COOKIES is just an array that contains the cookies recevied.

    To unset a cookie you do this
    Code PHP:
    setcookie($name ,'',time()-1,'/');

    You practically set a cookie with a expiring date in the past.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhmmm... maybe I worded it wrong. I'm doing a login part of a site, where you can log in, and check a "Remember me" checkbox, which sets a cookie. The unsetting a cookie is for the logout part, so the next time the site's visited from that computer, it will find no cookie existing, and will give the login.

  5. #5
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes my reply is about that case.

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks

  7. #7
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It can be a good idea to set the timestamp further into the past. Reason being is that the client's browser users the timestamp to determine when to expire (remove) the cookie.

    If the users clock is wrong, or in a different timezone then the cookie may not be removed straight away.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •