Home » Magento

Magento: Redirect Customer to Login page if not logged in

10 October 2011 Share/Bookmark

If you are developing a module which needs to give access to its content only to logged in user then the preDispatch function will be very useful. This dispatches event before action.

Just write the following function in your module’s controller and customer log in is checked before each of your controller action.

/**
 * Checking if user is logged in or not
 * If not logged in then redirect to customer login
 */
public function preDispatch()
{
	parent::preDispatch();

	if (!Mage::getSingleton('customer/session')->authenticate($this)) {
		$this->setFlag('', 'no-dispatch', true);
	}
}

Hope this helps. Thanks.

From Mukesh Chapagain's Blog, post Magento: Redirect Customer to Login page if not logged in

email

php magento mukesh chapagain

Get New Post by Email
RSS Feed Subscribe RSS Feed
  • Vineetsajwan

    Great!!!!!!!!!!
    Thanks