views:

60

answers:

2

I was using the code below to delete cookies and everything worked fine. A few days ago, I began hosting the code somewhere else and it will not longer delete the cookie.

Any ideas?

if( $_COOKIE )
{
     foreach( $_COOKIE as $name => $value )
     {
          $params = session_get_cookie_params();

          unset($_COOKIE[$name]);
          setcookie($name, '', time()-43200, $params['path']);
          echo $name;
          echo '<br/>';
          echo $params['path'];
      }
}
A: 

Try this with out the echo statements.

Then do the following:

  1. Install Web Dev Toolbar for Firefox and restart it
  2. Do your steps to set the cookie, then view the cookie for the page using Web Dev Toolbar to confirm it is there
  3. Visit the page which removes the cookie, again view cookies for the page using Web Dev Toolbar - it will probably still be there.
  4. Finally visit another page on the site and check for the cookie again using Web Dev Toolbar
jakenoble
A: 

The cookie I was trying to delete was for my Facebook Connect app. When you logout of FB Connect, the cookie that was created does not get deleted. The cookie will not get deleted using the method I used if the callback URL in the website section of the FB Developer app has a WWW in it or if the user visits www.myapp.com

So I had to change the callback URL from http://www.myapp.com/ to http://myapp.com/ Then I had to do a rewrite in the .htaccess file to ensure the user is always visiting http://myapp.com w/o the WWW.

This seems really picky to me, but it works.

*Posted this and updated tags in case someone else runs into the same problem.

John