SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    St Petersburg, Russia
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to destroy cookies using PHP?

    I know how to set cookies using PHP. But how to destroy them? The only way I can invent is to set it expiry date one second in the future. However it is not quite elegant and I am not sure if the cookie will be destroyed imediately in this case or only after the user closes the browser.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    You have to set the date to a time PREVIOUS
    PHP Code:
    <?php
    // set the expiration date to one hour ago
    setcookie ("TestCookie"""time() - 3600);
    setcookie ("TestCookie"""time() - 3600"/~rasmus/"".example.com"1);
    ?>
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    St Petersburg, Russia
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In fact, in that case you should set at least one day in the past. After all local time difference can be up to one day for users in different parts of the world. So, one hour is not enough, right?

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set the cookie with no other values to kill it.
    PHP Code:
    $name="Your cookies name";
    setcookie($name); 

  5. #5
    SitePoint Guru enygmadae's Avatar
    Join Date
    Sep 2002
    Location
    Dallas, Tx.
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually, using the setcookie() function, if you don't pass the same values to the cookie as it had whren it was set (name, path, domain, security), my experience is that it changes made won't work correctly...
    PHP News, Views and Community: http://www.phpdeveloper.org


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
  •