How to check if an user is logged in or log out in Magento

This is Magento default feature. In top.link you can find login or logout link.But if you want to put somewhere login/logout button then you need to check whether a user logged in or not by the code given below.

if ($this->helper('customer')->isLoggedIn() )
echo '<a href="<?php echo $this->getUrl('customer/account/login/');?>">Login</a>';
echo '<a href="<?php echo $this->getUrl('customer/account/logout/');?>">Logout</a>';

No comments:

Post a Comment