Magento Snippet: How to set and get cookies in Magento


Posted by Andrew McCombe on Mon Feb 22, 2016

Here’s how to set and get cookies in Magento:

Set:

Mage::getSingleton('core/cookie')->set(
                'cookieName', 
                'cookie value;, 
                time() + (10 * 365 * 24 * 60 * 60),
                '/'
            );

Get:

Mage::getSingleton('core/cookie')->get('cookieName'); 
// will return the cookie value or false/null

Delete:

Mage::getSingleton('core/cookie')->delete('cookieName');