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)
  • Magento 1 Extensions
    • Customer Experience
      • Customer Group Selector / Switcher
      • Customer Redirect Pro
      • Store Restriction Pro
    • Payment Gateways
      • E-Path Payment
    • Import / Export
      • Mass Importer Pro(Price)
    • Content Management
      • jQuery Sliders Pro (Nivo Slider)
  • Free Extensions
    • Magento 2 Extensions
      • M2 Easy Template Path Hints
      • M2 Custom Shipping
      • M2 Preview/Visit Catalog
      • M2 Product Attachment
      • M2 Cart Discount Limiter
      • M2 Product Discount Label
      • M2 Store View Pricing
      • M2 Disable Customer Registration
    • Magento 1 Extensions
      • Easy Template Path Hints
      • jQuery Lightboxes (Fancybox, Pirobox, Lightbox Clone, prettyPhoto)
      • Frontend Links Manager
      • Zopim Live Chat
      • Admin Login Locale Selector
      • Custom PDF Invoice Layout
      • PayWay Payment
      • Tell A Friend
      • Store Restriction
      • Custom Login Redirect
  • 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)
  • Magento 1 Extensions
    • Customer Experience
      • Customer Group Selector / Switcher
      • Customer Redirect Pro
      • Store Restriction Pro
    • Payment Gateways
      • E-Path Payment
    • Import / Export
      • Mass Importer Pro(Price)
    • Content Management
      • jQuery Sliders Pro (Nivo Slider)
  • Free Extensions
    • Magento 2 Extensions
      • M2 Easy Template Path Hints
      • M2 Custom Shipping
      • M2 Preview/Visit Catalog
      • M2 Product Attachment
      • M2 Cart Discount Limiter
      • M2 Product Discount Label
      • M2 Store View Pricing
      • M2 Disable Customer Registration
    • Magento 1 Extensions
      • Easy Template Path Hints
      • jQuery Lightboxes (Fancybox, Pirobox, Lightbox Clone, prettyPhoto)
      • Frontend Links Manager
      • Zopim Live Chat
      • Admin Login Locale Selector
      • Custom PDF Invoice Layout
      • PayWay Payment
      • Tell A Friend
      • Store Restriction
      • Custom Login Redirect
  • 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
Tweet
Share7
Pin
7 Shares

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.

Tweet
Share7
Pin
7 Shares

Related posts:

  1. Custom Redirect Pro V2.0.0 – Redirect customer after login, logout, register, etc.
  2. Clear abandoned cart items during login in Magento
  3. Upgrading Magento from 1.6.0.0 to 1.6.1.0 via diff file
  4. Custom Login Redirect Pro: How to keep your customer logged in even after redirection to another store?
Categories Magento Tags current user, customer, customer_login, event-observer
Post navigation
500 Internal Server Error: Mismatch between target GID (XXX) and GID (XXX) of file
Clear abandoned cart items during login in Magento

Connect with Us

Popular Posts

  • Playing with Dates in Magento
  • Configuring Magento for Development / Debug Mode
  • Updating product prices in Magento in an easier & faster way
  • Updating product qty in Magento in an easier & faster way
  • Adding upload field in the contact form and send as an attachment

Recent Posts

  • Best FREE/Paid Magento 2 Extensions in 2022
  • Magento 2 Performance Optimization: Concerns & Solutions
  • Change Table Prefix for Magento 2 DB (After Installation)
  • Fix Region/State Dropdown not Loading on New Account Creation Page
  • What to Consider while Migrating from Magento 1 to Magento 2?

Search Blog

Categories

Apache Javascript jQuery Latest Linux Mac OS-X Magento Magento 2 Mysql Nginx PHP Ruby Updates Web Service

Archives

Tags

lightbox announcement regular price toolbar magento2 special price SSH eav utility functions backup script catalog product curl event-observer payment method Zend_Debug product price cms pages mysql Custom Login Redirect Pro csv attribute code snippets group price backup custom shipping easy template path hints mass importer pro Debugging Store Restriction Pro price importer backup magento collection export / import shipping method tier price bash XML advanced search shell .htaccess cms shipping magento backup stock inventory
MagePsycho Affiliate Program

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
© 2025 MagePsycho Store. All Rights Reserved.