How to Check customer or is logged in or not?

Source Code for check Customer:



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


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
    $session->addError(Mage::helper('customer')->__('Customer with email (%s) is already logged in.', $customer->getEmail()));

Source Code for check Admin:

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

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

Leave your comments

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s