I have a custom module with two controllers.
In the first controller (SetupController), if I were to set some session data like this:
Mage::getSingleton('core/session')
->setData('BuyerCookie', 'A1B2C3');
var_dump(Mage::getSingleton('core/session')->getData()); // I see the session value
Then, in another controller (TestController), if I try to retrieve the value from session like this:
var_dump(Mage::getSingleton('core/session')->getData()); // My session value is not there
Any ideas what might be happening? How do you set global session data and retrieve it?
I tried using cookie by utilising Mage::getSingleton('core/cookie') and it's doing the same thing.
2 Answers 2
Check the setting of session cookie management on admin panel.
I think that the cookie is not being set because of some wrong settings.
-
Cookie storage is set to
db(notfile). That's the only setting in terms of session setting I changed. What should I look for specifically in admin panel?Latheesan– Latheesan2016年03月14日 13:20:44 +00:00Commented Mar 14, 2016 at 13:20
i recommend this method to set session
Mage::getSingleton('core/session')->setBuyerCookie('A1B2C3');
and get it
Mage::getSingleton('core/session')->getBuyerCookie();
-
I will give this a go, but I thought the two methods were same (the one I am using and the one you recommended).Latheesan– Latheesan2016年03月14日 13:21:41 +00:00Commented Mar 14, 2016 at 13:21
-
once i got the same problem someone recommend this method..Qaisar Satti– Qaisar Satti2016年03月14日 13:22:36 +00:00Commented Mar 14, 2016 at 13:22
-
I tried this and it did not work. After doing this
Mage::getSingleton('core/session')->setBuyerCookie('A1B2C3');in mySetupControllerindex action, in the otherTestControllerindex action I did the following:echo '<pre>'; print_r(Mage::getSingleton('core/session')->getData()); exit;and this is what I am getting back (notice my data is not present): pastebin.com/raw/qANj0v1iLatheesan– Latheesan2016年03月14日 13:36:26 +00:00Commented Mar 14, 2016 at 13:36
preDispatch?Mage::getSingleton('core/session')->setBuyerCookie('A1B2C3');in mySetupControllerindex action, in the otherTestControllerindex action I did the following:echo '<pre>'; print_r(Mage::getSingleton('core/session')->getData()); exit;and this is what I am getting back (notice my data is not present): pastebin.com/raw/qANj0v1iMage::getSingleton('core/cookie')) and still getting the same issue. I don't know why the data is getting lost.