Magento Snippet: How to set and get cookies in Magento

February 22nd, 2016

Warning: This post is 8 years old. Some of this information may be out of date.

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');