Magento: Detect if admin is logged in in frontend pages

后端 未结 12 602
轻奢々
轻奢々 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:10

    If you are using cm redis session try this: (worked for me)

    $sesId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false ;
    if($sesId){
        $session = Mage::getSingleton('core_mysql4/session')->read($sesId);
    }
    $loggedIn = false;
    if($session)
    {
        if(stristr($session,'Mage_Admin_Model_User'))
        {
            $loggedIn = true;
        }
    }
    
    var_dump($loggedIn);
    

    because if you are using cm redis its rewrites db session module with its own model.

提交回复
热议问题