SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast imagenesis's Avatar
    Join Date
    Feb 2005
    Location
    Frederick, Maryland
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie Deletion Blatantly Doesnt Work

    I can set the cookies fine but this just doesnt work for some reason. I even tried both methods of setting the time. WHAT THE HELL IS WRONG?

    PHP Code:
    <?php
    setcookie
    ("friendId"""mktime(12,0,0,111990));
    session_start();
    if (!isset(
    $_SESSION['fId'])) {
    echo 
    $_COOKIE['friendId'];
    }
    unset(
    $_SESSION['fId']);
    // kill session variables
    $_SESSION = array(); // reset session array
    session_destroy();   // destroy session.
    echo $_COOKIE['friendId'];
    ?>
    The script prints out the cookie

    I tried it with this too: setcookie("friendId", "", time()-3600);

    Also, I checked my cookies in firefox and the script that sets the cookie also instead of overwriting a previously made cookie just adds a new one under the same name. So I have 2 cookies with diffirent value called friendID. Someone please help...

  2. #2
    Resident Code Monkey Chris Corbyn's Avatar
    Join Date
    Nov 2005
    Location
    Melbourne, Australia
    Posts
    713
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It only works if you reload the page, since the change needs to be made on the client before PHP can actually see it.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, cookies must be deleted by using the same paramters you used when you set the cookie. the path and domain fields may need to be added, as when you leave them blank, the values get infered for you.

    eg if you set the cookie in
    example.org/some/dir/

    and are trying to unset it in
    example.org/other/dir/

    your going to have trouble if you dont specify the path params. same goes for subdomains. yes, www is a subdomain.

    please have a read
    http://www.php.net/setcookie

  4. #4
    SitePoint Enthusiast imagenesis's Avatar
    Join Date
    Feb 2005
    Location
    Frederick, Maryland
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, that was the issue clamcrusher, I figured it out a bit before you posted All those online tutorials certainly imply a lot of things


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
  •