How to store a value in my session variable in Magento?

I use Magento and try to save the value in the session as follows in the index.php file, but the value is not saved.

$_SESSION['myvar'] = '1'; 

How should I do it?

thank

+47
php session magento
Jul 27 '10 at 5:29
source share
4 answers

Suppose you want to save the value of "Hello world" in the variable "welcome message" in a session. The code will look like this:

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

Now you want to repeat the "welcome message" elsewhere in your code / site.

 $outputMessage = Mage::getSingleton('core/session')->getWelcomeMessage(); echo $this->__($outputMessage); 
+73
Jul 27 '10 at 7:46 april
source share

Following the example of 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 enable [Mage-root] /app/Mage.php to call the code above!

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

+32
Jan 27 '11 at 13:12
source share
  Mage::getSingleton('core/session')->setMySessionVariable('MyValue'); $myValue = Mage::getSingleton('core/session')->getMySessionVariable(); echo $myValue; Take Look For More: 

Here is the code for Get, Set and Unset Session in Magento

Here is the code for Get, Set and Unset Session in Magento

+10
Nov 01 '13 at 19:08
source share
 frontend: Mage::getSingleton('core/session')->setYourNameSession($session_value); backend: Mage::getSingleton('admin/session')->setYourNameSession($session_value); 
+6
Jul 26 '13 at 2:36 on
source share



All Articles