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.

  • Do you set the session value within a controller action or earlier, like constructor or preDispatch? – mam08ixo Mar 14 '16 at 13:31
  • I set it within a controller action and try to retrieve it within a controller action also. – Latheesan Mar 14 '16 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 – Latheesan Mar 14 '16 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. – Latheesan Mar 14 '16 at 13:59
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.

  • 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? – Latheesan Mar 14 '16 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();
  • 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 Mar 14 '16 at 13:21
  • once i got the same problem someone recommend this method.. – Qaisar Satti Mar 14 '16 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 – Latheesan Mar 14 '16 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.