Magento set, get and unset session variables.

Magento session variable once is set, it can be used on any page. The examples below set, get and unset a varialbe Greeting, but any variable name would work.

Set a session variable, Greeting is the variable name, the prefix set is need to set this variable.
[code language=”php”]
Mage::getSingleton(‘core/session’)->setGreeting("hey how are you!");
[/code]

Retrieve the session variable Greeting using the get prefix.
[code language=”php”]
Mage::getSingleton(‘core/session’)->getGreeting();
[/code]

Unset the session variable Greeting using the uns prefix.
[code language=”php”]
Mage::getSingleton(‘core/session’)->unsGreeting();
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search