I have 3 Magento users with certain roles and access permission in backend end, i want to know that how many users where logged in, depends up on the logged In users user specific pop up will appear, Suppose i have 3 users called

  • 1.Don1
  • 2.Don2
  • 3.Don3

I want to know that who is currently logged in and depends upon the user role i need to show a popup magento, is there any method to find out the logged in users.

  • By magento users, do you mean magento admin panel users, or, frontend customers? Commented Aug 24, 2015 at 9:04

3 Answers 3


I assume you're talking about Admin users when you mention user role

This code should tell you the admins role

$admin_user_session = Mage::getSingleton('admin/session');
$adminuserId = $admin_user_session->getUser()->getUserID();
$role = Mage::getModel('admin/user')->load($adminuserId)->getRole()->getData();

I'd wrap it in an IF to make sure they're logged in before firing it, something like

    switch ($role) {
        case 'Don1':
            // Do something for Don 1
        case 'Don2':
            // Do something for Don 2
        case 'Don3':
            // Do something for Don 3
  • Error Call to a member function getUserId()
    – Naveenbos
    Commented Aug 24, 2015 at 12:52
  • Sorry, I've just edited my answer. Try getUserID (Capital I and D) Commented Aug 24, 2015 at 13:18
  • Alternatively you can try getId, or perhaps getID - Sorry, I don't have Magento infront of me so I'm unable to check properly. Commented Aug 24, 2015 at 13:19
$cursession = Mage::getSingleton('admin/session');
$userId = $cursession->getUser()->getUserId();
$role = Mage::getModel('admin/user')->load($userId)->getRole()->getData();

You can get role regarding data in the $role array. By using that, You can show your desired message.


To get logged in user in admin-end.

    $admin = Mage::getSingleton('admin/session')->getUser();
    if ($admin->getId()){
        echo $admin->getUsername();

To get logged in user role

$role_data = Mage::getModel('admin/user')->load($admin->getId())->getRole()->getData();

To get logged in user in front-end.

$customerSession = Mage::getSingleton('customer/session');
if($customerSession->isLoggedIn()) {
     $customerData = $customerSession->getCustomer();
     echo $customerData->getId();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.