Check if any particular customer is logged in or not


/ Published in: PHP
Save to your folder(s)

- Check if any particular customer is currently logged in or not.
- Get all the logged in customers with their recent activity.
- Courtsey: <a href="http://ka.lpe.sh">http://ka.lpe.sh</a>


Copy this code and paste it in your HTML
  1. require "app/Mage.php";
  2. umask(0);
  3. Mage::app();
  4. $collection = Mage::getModel('log/visitor_online')->prepare()->getCollection();
  5.  
  6. //Get all the customers that are logged in......
  7. foreach($collection->getData() as $cust) {
  8. echo 'Customer ID: '.$cust['customer_id'] . '<br/>';
  9. echo 'Last URL visited: '.$cust['last_url'] . '<br/>';
  10. echo 'First visit: '.$cust['first_visit_at'] . '<br/>';
  11. echo 'Last visit: '.$cust['last_visit_at'] . '<br/>';
  12. echo '======================<br/>';
  13. }
  14.  
  15. //Get any particular customer, if he's currently logged in or not.....
  16. $collection->addFieldToFilter('customer_id', 5)->addCustomerData(); //5 is customer ID of customer you want to check
  17. if($collection->count()) {
  18. echo 'Customer is logged in';
  19. } else {
  20. echo 'Customer is NOT logged in';
  21. }

URL: http://ka.lpe.sh/2013/04/25/magento-check-if-any-particular-customer-is-currently-logged-in/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.