Tag Archives: Magento Session

Magento Set, Retrieve and Unset Session Variables

To set, retrive and unset session variables in Magento

To Set a session variable:

1
2
3
4
<?php
$sesValue = 'Hello';
Mage::getSingleton('core/session')->setSessionValue($sesValue);
?>

To Retrieve a session variable:

1
2
3
4
<?php
$sesValue = '';
$sesValue = Mage::getSingleton('core/session')->getSessionValue();
?>

To Unset:

1
2
3
<?php
Mage::getSingleton('core/session')->unsSessionValue();
?>

Note: that ‘SessionValue’ can be any text but you need to ‘set’, ‘get’ and ‘uns’ prefixes are required.