Magento: How to Set,Get,Unset session variables

set-session-cokies

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>