1

I have this piece of code in a controller:

public function getiframeAction() {
    if (Mage::getSingleton('customer/session')->isLoggedIn())
        echo "Yes";
    else
        echo "no";
}

And it always returns "no", regardless the front-end user is logged in or not. How can I figure out what is going on?

Thank you

4
  • 1
    Is this action doing anything specifically custom that would cause it to use a different session? Try logging the results of Mage::getSingleton('customer/session')->getSessionId() and comparing it with your FE result. Feb 14, 2017 at 18:02
  • @Luke It returns the same as the FE session id. And no, the function has just the code I posted.
    – jfxipi
    Feb 14, 2017 at 19:50
  • Just for the record, the site has multiple stores, and if I echo the store code from the controller operation, it shows the default one instead of the code of the store I'm browsing
    – jfxipi
    Feb 14, 2017 at 19:57
  • Interesting. I think if you declare a controller in the typical fashion it should still be loading in the same store code as the rest of your site. You should be debugging into why the store code is different. Does your store use codes to identify them eg (example.com/uk) or is it more like example.co.uk. Feb 14, 2017 at 21:45

1 Answer 1

1

please use this function in your controller and then call it instead:

private function _getSession()
{
Mage::getSingleton('core/session', array('name' => 'frontend'));
return Mage::getSingleton('customer/session');
}

let me know whether it works.

1
  • Yes, it worked. Thanks! :D Dec 4, 2019 at 12:37

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.