Jump to content

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

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.