Jump to content

Overwrite cookie deletes it?


silkfire

Recommended Posts

I have some serious problem with my cookie setting script.

 

In my index file, a cookie is set by default if it's not already set. Lifetime: 1 month.

 

In my interface, I have a way to change settings, when the user presses okay, an AJAX call is issued which saves a cookie with the chosen settings.

If tried changing the expiry here to 1 month, 2 months, doesn't matter. The resulting script deletes my cookie for some reason. Why is this?

I've read to change cookie value you should use setcookie again (which I want, bc I want to extend the lifetime everytime user changes a setting), and not use the $_COOKIE variable to assign value.

 

I get response "deleted" which in practice deletes my cookie, plus it changes to Session when it's at least 1 month lifetime. What am I doing wrong?

 

if (isset($_POST['theme'])) {
   setcookie('theme', $_POST['theme'], strtotime('+2 month'));

   die();
}

 

 

1znuz2a.jpg

Link to comment
https://forums.phpfreaks.com/topic/264967-overwrite-cookie-deletes-it/
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.