silkfire Posted June 28, 2012 Share Posted June 28, 2012 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(); } Link to comment https://forums.phpfreaks.com/topic/264967-overwrite-cookie-deletes-it/ Share on other sites More sharing options...
silkfire Posted June 28, 2012 Author Share Posted June 28, 2012 Shuute. I found the problem. I never supplied the setting to the POST. An empty cookie value is the same as deleting it. Mea culpa =) Link to comment https://forums.phpfreaks.com/topic/264967-overwrite-cookie-deletes-it/#findComment-1357806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.