Results 1 to 12 of 12

Thread: delete cookies [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    74

    delete cookies [RESOLVED]

    hello,
    I have 3 pages that deals with cookies:

    addcookies.php
    <?
    $i=0;
    $prod=$_COOKIE['prod'];
    while (list ($name, $value) = each ($prod))
    $i++;

    $prod=$_GET['prod'];
    setcookie("prod[$i]",$prod);
    ?>

    delcookies.php
    <?
    $prod=$_COOKIE['prod'];
    while (list ($name, $value) = each ($prod))
    setcookie("prod[$name]","");
    ?>

    showcookies.php
    <?
    $prod=$_COOKIE['prod'];
    while (list ($name, $value) = each ($prod))
    echo "$name == $value<br>\n";
    ?>

    this cookies are holding array as values
    I am keep failing to delete all the array there is always one cell in the array that is left...

    anybody see something wrong in this code?

    if you cant help me base only on this code then tomorrow I will upload it to my server and you will see what I mean...
    Yair
    Last edited by yair24; Sep 8th, 2003 at 01:13 AM.
    -------------------------------------
    http://www.ybweb.com

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    first you have to set the cookie correcty. you set the name and value but not the time. and deleteing a cookie doesn't mean just delete the value.

    to set a cookie you have to do this

    setcookie("name_of_cookie", "value_of_cookie", time(),"/");

    to delete a cookie you have to do the exact oposite of when you set it. but the only thing that changes is teh time as you do the same time but just minus it.

    setcookie("name_of_cookie", "value_of_cookie", -time(),"/");

    your way will not work.

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    to delete a cookie you have to do the exact oposite of when you set it. but the only thing that changes is teh time as you do the same time but just minus it.
    Not necessarily. You can delete a cookie just by doing:

    Code:
    setcookie('cooke_name', '', time() - 3600);
    You don't have to specify the value or path.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    I know but he was deleting the value only with no time.

    you should have a path as I have seen many problems arise because the path was forgotten.

  5. #5
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    why dont they just make a "deletecookie()" function?

    -morrowasted

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    I know but he was deleting the value only with no time.

    you should have a path as I have seen many problems arise because the path was forgotten.
    I've never had a problem with it.

    why dont they just make a "deletecookie()" function?
    Why don't ya ask them?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by The Hobo
    I've never had a problem with it.
    you will

    actually, morrowasted had the problem. read this
    http://www.htmlforums.com/showthread...threadid=23074
    Last edited by phpman; Aug 20th, 2003 at 11:01 PM.

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    you will

    actually, morrowasted had the problem. read this
    http://www.htmlforums.com/showthread...threadid=23074
    For SETTING the cookie, yes, I agree with you and do understand why you should do that.

    For DELETING the cookie, I don't see why you would have a problem with not specifying the path?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    phpman, you go to htmlforums?

    ah, the days of my PHP youth... i'd probably make the same mistake today, actually, if i had never done cookies before!

    -morrowasted

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by The Hobo
    For SETTING the cookie, yes, I agree with you and do understand why you should do that.

    For DELETING the cookie, I don't see why you would have a problem with not specifying the path?
    because it has to be the same as when you created it. so specifing the path should be in there. I guess if you delete it without the path and it works that is fine, I just don't do it that way. if I create it one way I delete it the same way. save all teh trouble.

    but the fact remains that he didn't set the cookie correctly anyway.

    morrowasted: think about it

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    74

    thanks :)

    thanks for the help.

    Yair
    -------------------------------------
    http://www.ybweb.com

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    I guess if you delete it without the path and it works that is fine, I just don't do it that way. if I create it one way I delete it the same way. save all teh trouble.
    If no trouble exists, no trouble can be saved.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width