2

For some reason, magento clears session or customer session data after redirect? How will I save some data before it redirect to the next page into a session?

I tried adding session_write_close(); but this doesn't help.

Update:

Some actions do not retrieve Magento::getSingleton('core/session') whole data.

1
  • This then means your customer gets logged out after the redirect, which would be poor user experience. Rather than doing a workaround, saving the session data, it would be best to figure out why the session is clearing. Is there, by any chance, a 404 happening in the redirect (not the redirect itself, but some resource (be it image/css/js) on the redirected location? See this post: magento.stackexchange.com/questions/385/… - it may contain some helpful information
    – ProxiBlue
    Apr 25, 2015 at 23:44

1 Answer 1

0

If the session is not totally clear, you can try this:

To set data in the customer session:

$session = Mage::getSingleton("core/session",  array("name"=>"frontend"));  //load session variables
$session->setData("data", $data); //save your data in custom session variable

And then, To retrieve data from the customer session:

$data = $session->getData("data"); //get data from custom variable

This will store the data in the customer's session, and you can retrieve it after the redirect. If you're still having issues, make sure you're setting the session data before any redirects occur. Also, ensure that Magento's session storage is configured correctly and that sessions are being saved and not immediately cleared.

Your Answer

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

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