Magento: How to Set,Get,Unset session variables

Magento: How to Set,Get,Unset session variables

Commonly, session in Magento is handled by core session Module ‘core/session’. We use “set<session name>” to set a session variable. Look at the syntax and example below:

Mage::getSingleton('core/session')->set<Session name>('session variable'); // Syntax

$name = 'John';  // Example
Mage::getSingleton('core/session')->setMyname($name);

Likewise,“get<session name>” is used to get session variable. Look at the syntax and example below:

Mage::getSingleton('core/session')->get<Session name>();         // Syntax
Mage::getSingleton('core/session')->getMyname();                // Example

To unset the session use “uns<session name>”.Below is the syntax and example:

Mage::getSingleton('core/session')->uns<Session name>();          // Syntax
Mage::getSingleton('core/session')->unsMyname();                 // Example

Please contact us at manish@bay20.com or call us at +91-8800519180 for any support related to Magento. You can also visit the Magento development page to check the services we offer.