www.webdeveloper.com
Results 1 to 9 of 9

Thread: Cannot delete cookie

  1. #1
    Join Date
    Jul 2005
    Posts
    94

    Cannot delete cookie

    I have created a cookie in basic-html.php. The code I use is:
    Code:
    setcookie("webExamsTaken", implode(",", $examsTaken), time() + 60*60*24*30);
    I have another PHP program called delwecookies.php where I attempt to delete this cookie. The code I use here is:
    Code:
    setcookie("webExamsTaken", "", time() - 3600);
    echo "Cookie deleted.";
    The attempt to delete the cookie in delwecookies.php is failing. Can anyone please tell me why? Thank you.

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    quoted from a google search
    Quote Originally Posted by google search 'delete php cookie'
    There is a known problem with this, though. Although it works in most cases, there can be problems if a user's timezone is set wrongly. The safest way to completely delete a cookie is to use the following:

    setcookie("UsersName", "", mktime(12,0,0,1, 1, 1990));
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Although the cookie WILL be deleted when you send this: setcookie("webExamsTaken", "", time() - 3600); it will still exist in the script as $_COOKIE['webExamsTaken']. If that is a problem just unset it.
    PHP Code:
    unset($_COOKIE['webExamsTaken']); 

  4. #4
    Join Date
    Jul 2005
    Posts
    94
    Quote Originally Posted by chazzy
    quoted from a google search
    Thanks for that tip. I will use that from now on.

  5. #5
    Join Date
    Jul 2005
    Posts
    94
    Quote Originally Posted by bokeh
    Although the cookie WILL be deleted when you send this: setcookie("webExamsTaken", "", time() - 3600); it will still exist in the script as $_COOKIE['webExamsTaken']. If that is a problem just unset it.
    PHP Code:
    unset($_COOKIE['webExamsTaken']); 
    That may be my problem. I will check it out. Thanks.

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    yeah, it's important to note that cookies don't get saved until after the page is sent back to the browser from the server.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by chazzy
    ...
    Incidentally, (I'm using PHP 5.04/5.11) if I send
    PHP Code:
    setcookie('name'nulltime() -3600); 
    the header that actually gets sent to the user is very different. Here it is:
    Code:
    Set-Cookie: name=deleted; expires=Wed, 22-Dec-2004 09:36:45 GMT
    which is one year earlier not one hour earlier. It would seem PHP has some special built in handling when it realises a cookie is for deletion.

  8. #8
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Quote Originally Posted by bokeh
    ...
    are you sure your server time is correct?
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  9. #9
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles