Magento - Checking if an Admin and a Customer are logged in

Magento - Checking if an Admin and a Customer are logged in

July 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - Checking if an Admin and a Customer are logged in

Solving Magento Session Conflicts: Checking Admin and Customer Logins Simultaneously

As you’ve discovered, handling admin and customer sessions simultaneously in Magento can be tricky due to session conflicts. In this blog post, we’ll tackle the issue of checking if both an admin and a customer are logged in without overwriting or losing session data.

Understanding the Session Conflict Issue

Magento uses separate session names for frontend (frontend) and backend (adminhtml). When you initiate sessions sequentially like you did:

Mage::getSingleton('core/session', array('name'=>'frontend') );
$session=Mage::getSingleton('customer/session', array('name'=>'frontend') );

// ...

Mage::getSingleton('core/session', array('name'=>'adminhtml') );
$adminsession = Mage::getSingleton('admin/session', array('name'=>'adminhtml'));

You’re actually closing the previous session before starting a new one. This is why you couldn’t get both the admin and customer data correctly.

The Proper Approach: Using Multiple Sessions Simultaneously

To resolve this, we need to open multiple sessions simultaneously without closing them. We can achieve this by using the Mage::getModel('core/session') instead of Mage::getSingleton.

Here’s how you should modify your code:

require_once '../app/Mage.php';
umask(0) ;

Mage::app();

// Checking for customer session
$frontendSession = Mage::getModel('core/session');
$frontendSession->start();

$session = Mage::getSingleton('customer/session', array('name'=>'frontend') );

if ($session->isLoggedIn()) {
    echo "Customer is logged in";
} else {
    echo "Customer is not logged in";
}

// Checking for admin session
$adminhtmlSession = Mage::getModel('core/session');
$adminhtmlSession->start();

$adminsession = Mage::getSingleton('admin/session', array('name'=>'adminhtml'));

if($adminsession->isLoggedIn()) {
    echo "Admin Logged in";
} else {
    echo "Admin NOT logged in";
}

How This Fix Works

By using Mage::getModel('core/session'), we’re creating new instances of the core session model without closing any existing sessions. We then explicitly start each session before initiating the respective customer or admin session.

This ensures that both sessions remain open and accessible simultaneously, allowing you to check for both login statuses correctly.

Conclusion

In Magento 1.x, handling multiple simultaneous sessions can be complex due to its reliance on singletons and session naming conventions. By understanding how Mage::getSingleton and Mage::getModel differ in behavior, we’ve been able to solve the session conflict issue you encountered.

Remember, for better maintainability and security, consider upgrading to a newer version of Magento that addresses these core issues more robustly.

For more advanced techniques on handling sessions and user authentication in Magento, check out our comprehensive guide at Laravel Company.

Happy coding!

Admin Customers Errors

Our network