Home » Magento10 October 2011

Magento: Redirect Customer to Login page if not logged in

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

php magento mukesh chapagain

Get New Post by Email

Find me on

Facebook Twitter Google+ LinkedIn RSS Feed
  • Vineetsajwan

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