How to check that a customer is logged-in or not, Magento

February 12, 2016
Posted by admin 2:22 AM

How to check that a customer is logged-in or not and to get the information of that logged in customer 

1. We will use below code to check customer is logged in or not by using customer session of Magento.

 Mage::getSingleton('customer/session')->isLoggedIn();

 

2. If the customer session exists we can get information of that customer .

<?PHP 

if(Mage::getSingleton('customer/session')->isLoggedIn())

{

$customerObj  = Mage::getSingleton('customer/session')->getCustomer();

 $customerId   = $customerObj->getId();

 $customerData = Mage::getModel('customer/customer')->load($customerId)->getData();

   Print_r($customerData);

}

else

{

 echo "Customer Not logged IN";

}

?>