Skip to content Skip to sidebar Skip to footer
Reading Time: < 1 minute

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.


$orderDiscount= 'orderDiscount';
$discountValue = 10;
// set cookie
Mage::getModel('core/cookie')->set($orderDiscount, $discountValue);

Magento get all cookies data/values


Magento get specific cookie data/value

// get above example cookie value(orderDiscount)

Magento delete cookie data/value

  Mage::getModel('core/cookie')->delete($name, $path, $domain, $secure, $httponly);


// Delete above example cookie value(orderDiscount)

You can refer more information from app\code\core\Mage\Core\Model\Session\Abstract\varien.php of line 84.