Jump to content

[SOLVED] delete cookie


tivrfoa

Recommended Posts

hello!

 

if I create the cookie this way:

setcookie('cookieName','cookieValue',0);

I can delete the cookie:

setcookie('cookieName', '', mktime(12,0,0,1, 1, 1990));

but I can't delete when I specify the path:

setcookie('cookieName', 'cookieValue', 0, "/");

 

could someone help me? what am I doing wrong?

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/137562-solved-delete-cookie/
Share on other sites

setcookie('cookieName', '', time()-3600);

 

That would be easier than the mktime. But the reason is you did not specify the path when creating the cookie. Try specifying the path and using this:

 

setcookie('cookieName','cookieValue',time()+3600, "/"); // for one hour at path /

 

setcookie('cookieName', '', time()-3600, "/");

Link to comment
https://forums.phpfreaks.com/topic/137562-solved-delete-cookie/#findComment-718981
Share on other sites

thanks rhodesa and premiso!

 

That would be easier than the mktime.

It's because I read that although it works in most cases, there can be problems if a user's timezone is set wrongly.

source: http://www.freewebmasterhelp.com/tutorials/cookies/2

 

I could see that. You could do this to thwart that issue...

 

setcookie('cookieName', '', time()-(3600*48), "/"); // set it to 2 days behind

 

=)

Link to comment
https://forums.phpfreaks.com/topic/137562-solved-delete-cookie/#findComment-719035
Share on other sites

thanks rhodesa and premiso!

 

That would be easier than the mktime.

It's because I read that although it works in most cases, there can be problems if a user's timezone is set wrongly.

source: http://www.freewebmasterhelp.com/tutorials/cookies/2

 

I could see that. You could do this to thwart that issue...

 

setcookie('cookieName', '', time()-(3600*48), "/"); // set it to 2 days behind

 

=)

 

or just set it to 1:

setcookie('cookieName', '', 1 "/");

Link to comment
https://forums.phpfreaks.com/topic/137562-solved-delete-cookie/#findComment-719050
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.