Jump to content

Destroying Cookie


gerkintrigg

Recommended Posts

Hi all...

I have searched but can't find a way to destroy a cookie easily using PHP. I want to do it so that all session and cookie info is removed when the user logs out. I have worked most of it out, but removing the cookies is causing problems.

 

Please help.

 

Ta,

Link to comment
Share on other sites

Hi...

Thanks for the info, but I have tried that, and it doesn't seem to work (I dunno why).

 

I'm using this code:

setcookie ("username", "", time() - 3600);
setcookie ("password", "", time() - 3600);

I know I'm naming the cookie correctly, but whenever I go to http://www.nextdaygraphics.com homepage, it logs me in automatically anyway.

 

I just want it to delete the cookie when i log out. Any suggestions are very welcome.

Link to comment
Share on other sites

I found this on the user comments at php.net:

 

Here is problem I ran into during a recent bout with IE7 and cookies.  IE will not delete a cookie value if the time is set to the past.  It will hold the value no matter how far in the past you set the "expire" value.  IE7 is the only browser I have had problems with - so here is the solution I came up with.

 

<?PHP

//check to see how to set the cookie

$Browsertype = $_SERVER['HTTP_USER_AGENT'];

$Parts = explode(" ",$Browsertype);

$MSIE = array_search("MSIE",$Parts);

               

if($MSIE)

{

setcookie("name", "", time()+20000);

}

else

{

setcookie("name", "", time()-20000, "/", ".domain.com" );

}

 

?>

Link to comment
Share on other sites

If you're using Firefox, someone has also posted comments about deleting cookies for it.

The above example does not look like it will work for deleting a cookie for IE7...it looks like it just extends it, or deletes the value for it.

 

Also, make sure you're using the full domain and all of the parameters. If you set it for domain.com, then delete it for www.domain.com and then you're on domain.com again, the cookie will show.

 

It might not even be the cookie, it might be your code. We'd need to SEE the code to tell.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.