Magento: Detect if admin is logged in in frontend pages

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

    It is quite simple but not a recommended solution. I myself spend number of hours to do this. For, windows based server try below solution:

    $sessionFilePath = Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
    $sessionFile     = file_get_contents($sessionFilePath); 
    $exp_cookie   = explode(';',$sessionFile);
    if(count($exp_cookie)   >   100)
    {
      return "login";
    }
    return "expire";    
    

    For, Linux based server try below solution:

    $sessionFilePath = Mage::getBaseDir('session').DS.'sess_'.$_COOKIE['adminhtml'];
    $sessionFile     = file_get_contents($sessionFilePath); 
    $exp_cookie   = explode('--',$sessionFile)
    if(count($exp_cookie)   >   10)
    {
      return "login";
    }
    return "expire";
    

    Thanks, Kashif

提交回复
热议问题