1

Is that possible when a user visit on the website, its ask for login and then after login user will access the website. So basically only login user will access the website.

2 Answers 2

1

Added below php code in your theme/template/page/html/head.phtml file:

if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
    //not logged in
    $cnt = Mage::app()->getRequest()->getControllerName(); // return controller name

    $action = Mage::app()->getRequest()->getActionName(); // return action name

    $action = Mage::app()->getRequest()->getRouteName(); // return routes name

    if ($cnt != "account" && $action != "account" && $action != "login") {
        Mage::app()->getFrontController()->getResponse()->setRedirect('customer/account/login')->sendResponse();
    }
}

Hope this will help you.

2
  • You can feel free to up vote my answer thanks.
    – Nits
    Commented Apr 28, 2016 at 10:53
  • How can i set, the registered customer only use the contact form.
    – Gem
    Commented Apr 6, 2018 at 5:56
0

There are several modules available for what you want to achieve:

The idea is basically to use an observer on the controller_action_predispatch event, check if the user is logged in and if the customer is not logged in, redirect to the login/register page.

4
  • thanks, but I don't want to use any extension or module. Could you please explain, how would I setup "controller_action_predispatch" in default Magento.
    – Mace Long
    Commented Apr 28, 2016 at 10:13
  • To be honest your last comment shows the urgent need for an extension for your purpose and not a hack like it looks.
    – Michael
    Commented Apr 28, 2016 at 10:19
  • @MaceLong check the github repo from the first link I posted, the module is free Commented Apr 28, 2016 at 10:22
  • How can i set, the registered customer only use the contact form.
    – Gem
    Commented Apr 6, 2018 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.