Magento: Detect if admin is logged in in frontend pages

后端 未结 12 606
轻奢々
轻奢々 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 01:07

    The above solutions doesn't work!

    Here is a solution that works ( its not that clean ! but this will work anywhere in your application in phtml view or model or controller or helper ! )

    $sesId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false ;
    $session = false;
    if($sesId){
        $session = Mage::getSingleton('core/resource_session')->read($sesId);
    }
    $loggedIn = false;
    if($session)
    {
        if(stristr($session,'Mage_Admin_Model_User'))
        {
            $loggedIn = true;
        }
    }
    var_dump($loggedIn);// this will be true if admin logged in and false if not
    

提交回复
热议问题