Skip to content
MagePsycho Blog
MagePsycho Blog
  • Magento 2 Extensions
    • Customer Experience
      • M2 Customer Group Selector Pro
      • M2 Customer Redirect Pro
      • M2 Store Restriction Pro
    • Checkout / Sales Motivation
      • M2 Region & City Manager
      • M2 Sales Promotion Pro (FREE Gift)
    • Payment Gateways
      • M2 E-Path Payment
    • Import / Export
      • M2 Mass Importer Pro (Price)
  • Free Extensions
    • Developer Tools
      • M2 Easy Template Path Hints
      • M2 Preview/Visit Catalog
    • Sales / Admin
      • M2 Disable Customer Registration
      • M2 Custom Shipping
    • Catalog / Pricing
      • M2 Product Attachment
      • M2 Product Discount Label
      • M2 Store View Pricing
      • M2 Cart Discount Limiter
    • SEO / Marketing
      • M2 SEO Suite
  • Services
  • Blog
  • Magento 2 Extensions
    • Customer Experience
      • M2 Customer Group Selector Pro
      • M2 Customer Redirect Pro
      • M2 Store Restriction Pro
    • Checkout / Sales Motivation
      • M2 Region & City Manager
      • M2 Sales Promotion Pro (FREE Gift)
    • Payment Gateways
      • M2 E-Path Payment
    • Import / Export
      • M2 Mass Importer Pro (Price)
  • Free Extensions
    • Developer Tools
      • M2 Easy Template Path Hints
      • M2 Preview/Visit Catalog
    • Sales / Admin
      • M2 Disable Customer Registration
      • M2 Custom Shipping
    • Catalog / Pricing
      • M2 Product Attachment
      • M2 Product Discount Label
      • M2 Store View Pricing
      • M2 Cart Discount Limiter
    • SEO / Marketing
      • M2 SEO Suite
  • Services
  • Blog

Home » Magento » How to check if the customer is already logged in from another location?

How to check if the customer is already logged in from another location?

June 22, 2019May 1, 2012 by Raj KB

In order to check whether the current user is logged in or not, we can easily find out using the following code:

if(Mage::getSingleton('customer/session')->isLoggedIn()){
	//customer is logged in
}

Note: This code only checks the current session of a customer using the current browser.

Case:

Suppose if a user with email: [email protected] is already logged in via one browser, the same user tries to login via another browser or another user who knows the username/password tries to log in from another location then how will you check if the customer with that email is already logged in?

Solution:

Well, it’s simple enough.
You can create Event/Observer that hook into the event: customer_login and check as follows in the observer method:

$customer = $observer->getEvent()->getCustomer();
$log = Mage::getModel('log/visitor_online')->getCollection()->addFieldToFilter('customer_id', $customer->getId())->getFirstItem();
if($log->getId()){ //current user is already logged in / online from another location	
	Mage::getSingleton('customer/session')->logout();
	$session->addError(Mage::helper('customer')->__('Customer with email (%s) is already logged in.', $customer->getEmail()));
	Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
	return;
}

Notes: If you browse the table: log_visitor_online you can see it stores the details of currently logged in customers and guests.

Above code just tries to check if current customer details are on the table or not. If customer data is present it means he/she is already logged in and online else this will be his/her fresh login.

Categories Magento Tags current user, customer, customer_login, event-observer
500 Internal Server Error: Mismatch between target GID (XXX) and GID (XXX) of file
Clear abandoned cart items during login in Magento

Search Blog

Categories

  • Apache (4)
  • Javascript (4)
  • jQuery (7)
  • Latest (11)
  • Linux (14)
  • Mac OS-X (3)
  • Magento (74)
  • Magento 2 (16)
  • Mysql (13)
  • Nginx (2)
  • PHP (11)
  • Ruby (1)
  • Updates (4)
  • Web Service (2)

Recent Posts

  • Change Table Prefix for Magento 2 DB (After Installation)
  • Fix Region/State Dropdown not Loading on New Account Creation Page
  • Tinkerwell: Tinker with your local/remote PHP & Magento 2 Code
  • How to Install Multiple Versions of PHP on Ubuntu?
  • Import Product Reviews in Magento via SQL

Archives

Quality Magento Commerce extension & service provider since 2009

Connect with us

Navigation

  • About Us
  • Services
  • Rewards Program
  • Affiliate Program
  • Privacy & Policy
  • Terms & Conditions

Support

  • Contact Us
  • Submit Ticket
  • FAQs

Resources

  • Blog
  • Knowledge Base
  • Documentation
  • Sitemap
  • We Accept
© 2026 MagePsycho Store. All Rights Reserved.