Magento: Get Set Unset Session

Here are code to Get, Set, and Unset Session in Magento.

Set session with variable Name ‘testing_magento‘. The session value here is ‘hello‘.

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

Get session ‘testing_magento’

$test = Mage::getSingleton(‘core/session’)->getTestingMagento();

Unset session

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

Note: Use customer or core session in frontend. Use adminhtml session in the backend.

Core Session:- Mage::getSingleton(‘core/session’)
Customer Session:- Mage::getSingleton(‘customer/session’)
Admin Session:- Mage::getSingleton(‘adminhtml/session’)

Hope it helps. Thanks.