I am running PHP Magento 1.4.1.1 and I am storing a cookie with user preferences.
I use this to store the cookie.
umask(0);
Mage::app();
Mage::getModel('core/cookie')->set('lunch', 'user likes tuna fish', (60*60*24));
Now this works fine to save the cookie... but if I try and update the or delete the cookie I don't see any change.
I try and set the cookie with new data like so:
umask(0);
Mage::app();
Mage::getModel('core/cookie')->set('lunch', 'user likes hamburgers', (60*60*24));
and usually a second cookie is created with the exact same name, domain and path.
Also if I try to delete instead of change I use this:
umask(0);
Mage::app();
Mage::getModel('core/cookie')->delete('lunch');
with no changes to the cookie.
I have also used delete like this:
Mage::getModel('core/cookie')->delete('lunch', '/', 'www.domain.com');
Mage::getModel('core/cookie')->delete('lunch', '/', '.domain.com');
Mage::getModel('core/cookie')->delete('lunch', '/', 'domain.com');
With no luck either.
Any ideas?
FYI... I am outside of root folder.
Ok, on this one I ended up solving myself... but was causing the problem. The variable I was passing while using set was not set itself... send NULL or FALSE. apparently Magento won't set a cookie if this is FALSE or NULL
So again solution was Make sure value is set.
Mage::getModel('core/cookie')->set('lunch', $SET_VALUE_HERE, (60*60*24));
Also I seemed to have more luck using set with a zero at the end to kill the cookie.
Mage::getModel('core/cookie')->set('lunch', $SET_VALUE_HERE, 0 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.