Skip to content Skip to sidebar Skip to footer

Magento check admin is logged or not and get admin details

Reading Time: < 1 minute

Here is a simple script to check admin is logged or not and if logged get admin details of Magento.You can call to the session and the call to user function to get all details.

     $userDetails = Mage::getSingleton('admin/session');    // Get data from the session
     $userID      = $userDetails->getUser()->getUserId();   // Get user ID
     $userID      = $userDetails->getUser()->getEmail();   // Get user Email

Following example will show check admin is logged or not.

   //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()){
        // admin login
   }
   else
   {
       //  not admin login
   }