How to check customer is logged in or not in Magento

magento

In Magento we can check that is customer logged in or not and we can get its all necessary details by its customer id too.
To get customer details we can write below code into any php or phtml file and it will load all the details of the user logged in.
So please check below code to check if customer is logged in or not :-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>How to check customer is logged in or not in Magento</title>
</head>
<body>
<!-- Create New Group and add attribute and Assign Attribute to group-->
<?php
if(Mage::getSingleton('customer/session')->isLoggedIn())
{  
	//Get Customer User Id
	$customer_session = Mage::getSingleton('customer/session');
	$customer_id      = $customer_session->getCustomer()->getId();
}
?>
Posted in Uncategorized