PHP Cookie Problem?

Discussion in 'PHP' started by trafficke, Nov 13, 2009.

  1. #1
    First, on one page, I tried to set a cookie.
    <?php
    if (isset($_COOKIE["limited"]))
     echo "OLD COOKIE!";
    else
     setcookie("limited", "true", time()+3600);
     echo "set";
    ?>
    PHP:
    Then, on another page, I tried to delete it.
    <?php
     setcookie("limited", "true", time()-3600);
    if (isset($_COOKIE["limited"]))
     echo "still here";
    else
     echo "gone!";
    ?>
    PHP:
    I could not delete the cookie. I know that this is the problem because I am using Google Chrome where you can view all the cookies, and because the deleting script also has an if statement to check if the cookie has been deleted.

    What is wrong?
     
    trafficke, Nov 13, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think when deleting a Cookie you also need to set it's value to blank, whilst the expiration date is in the past (which you are already doing)

    So try something like:


    
    setcookie("limited", "", time()-3600);
    
    PHP:
     
    wd_2k6, Nov 13, 2009 IP