Magento: Detect if admin is logged in in frontend pages

后端 未结 12 629
轻奢々
轻奢々 2021-02-04 00:09

I have created a magento extension. I want to implement access to the extension. The extension creates a page in frontend and i want only admin to access that page. So basically

12条回答
  •  无人共我
    2021-02-04 00:59

    This code will works

    //get the admin session
    Mage::getSingleton('core/session', array('name'=>'adminhtml'));
    
    //verify if the user is logged in to the backend
    if(Mage::getSingleton('admin/session')->isLoggedIn()) {
      //do stuff
    }
    else
    {
      echo "404 page not found";
    }
    

    OR

    $adminsession = Mage::getSingleton('admin/session', array('name'=>'adminhtml'));
    
    if($adminsession->isLoggedIn()) {
        //do stuff
    } else {
        echo "404 page not found";
    }
    

    Did you try to dump the $_SESSION variable? Maybe it will help you get on the right track.

提交回复
热议问题