Magento Set, Retrieve and Unset Session Variables

Posted: April 20th, 2011 | Author: | Filed under: magento | 4 Comments »

To set a Magento session variable:

$myValue = 'Hello World';
Mage::getSingleton('core/session')->setMyValue($myValue);

To Retrieve:

$myValue = '';
$myValue=Mage::getSingleton('core/session')->getMyValue();

To Unset:

Mage::getSingleton('core/session')->unsMyValue();

Note that ‘MyValue’ can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Add Linkshare Pixel To Magento
  2. php: Send xml/soap to Secured Server

4 Comments on “Magento Set, Retrieve and Unset Session Variables”

  1. 1 wav to mp3 said at 10:08 am on April 29th, 2011:

    I enjoyed this! Well done!

  2. 2 Jonetta said at 11:53 pm on May 10th, 2011:

    Got it! Thanks a lot again for hleipng me out!

  3. 3 David said at 10:01 pm on July 29th, 2011:

    This wasn’t actually that helpful. At this point in the game I have a good handle on magic methods. But how do I mess with a session that’s not the one I’m currently in? I’m working with a swf and that doesn’t count as the same session apparently.

  4. 4 john said at 10:58 am on May 14th, 2012:

    Great..dude…thanks..


Leave a Reply