How do I save value in my own session variable in Magento? How do I save value in my own session variable in Magento? php php

How do I save value in my own session variable in Magento?


Let's say you want to save the value "Hello world" to the "welcome message" variable in the session. The code would be :

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

Now you want to echo the "welcome message" somewhere else in your code/site.

$outputMessage = Mage::getSingleton('core/session')->getWelcomeMessage();echo $this->__($outputMessage);


Following the example given by Ali Nasrullah, I would do:

$session = Mage::getSingleton("core/session",  array("name"=>"frontend"));// set data$session->setData("device_id", 4);// get data$myDeviceId = $session->getData("device_id");

Make sure you include [Mage-root]/app/Mage.php befor calling the code above!

@Ali Nasrullah: Pass the value of device:id as second parameter of the setData function.


  Mage::getSingleton('core/session')->setMySessionVariable('MyValue');   $myValue  =  Mage::getSingleton('core/session')->getMySessionVariable();  echo $myValue; Take Look For More: 

Here are code to Get, Set, and Unset Session in Magento

Here are code to Get, Set, and Unset Session in Magento