Magento provides very easy way to handle Cookie and session.
Magento session:
>> Magento session is handle by core Module 'core/session'. Here is the way to save Session in magento
$session = Mage::getSingleton("core/session");
$session->setData("username", "value"); //This will store a session variable name "username"
OR
$session->setUsername("value");
To get This session value we can use one of these following ---
$session->getData("username");
OR
$session->getUsername();
>> And session can be removed with setting session variable null
$session->setData("username", null);
$session->setUsername("");
=========================================================
Cookie Handling in Magento:
>> Setting cookie
Mage::app()->getCookie()->set('cookie_name', "cookie_value", $lifetime,$domain,$httponly);
>> Getting cookie in magento
Mage::app()->getCookie()->get('cookie_name');
No comments:
Post a Comment