How to set,get and unset session value in Magento

setting session variables in Magento is very easy.We set session variable name in customer session object. Look at the following code:

How to set session value in customer object.

Mage::getSingleton(‘customer/session’)->setMyValue(“variable”);

How to set session value in core session object.

Mage::getSingleton(‘core/session’)->setMyValue(“variable”);

This piece of code sets the session variable setMyValue to the value of “variable”.

How to get session value back.

Mage::getSingleton(‘customer/session’)->getMyValue(“variable”);

How to get session value in core session object.

Mage::getSingleton(‘core/session’)->getMyValue(“variable”);

How to unset session value

Mage::getSingleton(‘customer/session’)->unsMyValue();

How to unset session value in core session object.

Mage::getSingleton(‘core/session’)->unsMyValue();