Magento: Check if any particular customer is currently logged in
Let’s say you want to check if any particular customer is currently logged in to your site or not. Or let’s check how many customers with their customer IDs and other activities are online on your store.
This little script will help you in finding all the currently active OR any particular customer(s) active in your store.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | require "app/Mage.php";
umask(0);
Mage::app();
$collection = Mage::getModel('log/visitor_online')->prepare()->getCollection();
//Get all the customers that are logged in......
foreach($collection->getData() as $cust) {
echo 'Customer ID: '.$cust['customer_id'] . '<br/>';
echo 'Last URL visited: '.$cust['last_url'] . '<br/>';
echo 'First visit: '.$cust['first_visit_at'] . '<br/>';
echo 'Last visit: '.$cust['last_visit_at'] . '<br/>';
echo '======================<br/>';
}
//Get any particular customer, if he's currently logged in or not.....
$collection->addFieldToFilter('customer_id', 5)->addCustomerData(); //5 is customer ID of customer you want to check
if($collection->count()) {
echo 'Customer is logged in';
} else {
echo 'Customer is NOT logged in';
} |
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (1)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Useful Links
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress