How to magento access cookie data or create, read, and delete cookie in magento? Magento Mage_Core_Model_Cookie class can be use to get,delete and set cookie data.If you try to use normal php cookie to get data, sometimes not working.
Magento set cookie data/values
Mage::getModel('core/cookie')->set($name, $value, $period, $path, $domain, $secure, $httponly);
NOTE:name and value are required.Other parameters are optional and can be set as null.
Usage
$orderDiscount= 'orderDiscount'; $discountValue = 10; // set cookie Mage::getModel('core/cookie')->set($orderDiscount, $discountValue);
Magento get all cookies data/values
Mage::getModel('core/cookie')->get();
Magento get specific cookie data/value
// get above example cookie value(orderDiscount) Mage::getModel('core/cookie')->get('orderDiscount');
Magento delete cookie data/value
Mage::getModel('core/cookie')->delete($name, $path, $domain, $secure, $httponly);
Usage
// Delete above example cookie value(orderDiscount) Mage::getModel('core/cookie')->delete('orderDiscount');
You can refer more information from app\code\core\Mage\Core\Model\Session\Abstract\varien.php of line 84.