0

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.

asked Mar 14, 2016 at 13:13
4
  • Do you set the session value within a controller action or earlier, like constructor or preDispatch? Commented Mar 14, 2016 at 13:31
  • I set it within a controller action and try to retrieve it within a controller action also. Commented Mar 14, 2016 at 13:33
  • After doing this Mage::getSingleton('core/session')->setBuyerCookie('A1B2C3'); in my SetupController index action, in the other TestController index 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/qANj0v1i Commented Mar 14, 2016 at 13:37
  • I have also tried the same thing using cookie (i.e. Mage::getSingleton('core/cookie')) and still getting the same issue. I don't know why the data is getting lost. Commented Mar 14, 2016 at 13:59

2 Answers 2

0

Check the setting of session cookie management on admin panel.

I think that the cookie is not being set because of some wrong settings.

answered Mar 14, 2016 at 13:17
1
  • Cookie storage is set to db (not file). That's the only setting in terms of session setting I changed. What should I look for specifically in admin panel? Commented Mar 14, 2016 at 13:20
0

i recommend this method to set session

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

and get it

Mage::getSingleton('core/session')->getBuyerCookie();
answered Mar 14, 2016 at 13:20
3
  • I will give this a go, but I thought the two methods were same (the one I am using and the one you recommended). Commented Mar 14, 2016 at 13:21
  • once i got the same problem someone recommend this method.. Commented Mar 14, 2016 at 13:22
  • I tried this and it did not work. After doing this Mage::getSingleton('core/session')->setBuyerCookie('A1B2C3'); in my SetupController index action, in the other TestController index 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/qANj0v1i Commented Mar 14, 2016 at 13:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.