Google+

Pages

Saturday, February 16, 2013

Magento: Redirect to login page if user not login

Here is simple magento code to redirect to login page, if user is not logged in:

<?php
    $redirect_url = Mage::getUrl('customer/account/login/');
    $current_url = Mage::helper('core/url')->getCurrentUrl();
    if((!$this->helper('customer')->isLoggedIn()) && ($current_url != $redirect_url)){
        Mage::app()->getFrontController()->getResponse()->setRedirect($redirect_url);
    }
?>

Use this code and enjoy.. :)