I have this piece of code in a controller:

public function getiframeAction() {
    if (Mage::getSingleton('customer/session')->isLoggedIn())
        echo "Yes";
        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

  • 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. – Luke Rodgers Feb 14 '17 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 '17 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 '17 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. – Luke Rodgers Feb 14 '17 at 21:45

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.

  • Yes, it worked. Thanks! :D – ivanaugustobd Dec 4 '19 at 12:37

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.