0

I want to set restriction to access frontend for users that are not logged-in to admin panel (same browser or not). Means user who is not logged in admin panel should not access frontend and should be redirected maintenance page.

I think it's possible by IP Address by editing index.php.

1
  • If you want it for different brwosers, you should go with Princes solution ... otherwise my answer should also work.
    – sv3n
    Jun 6, 2017 at 16:49

3 Answers 3

0

Try below free extension which will fulfill your requirement.

https://www.magentocommerce.com/magento-connect/maintenance-mode-4.html

https://www.magentocommerce.com/magento-connect/easy-site-maintenance.html

These extensions have a facility to set admin access so if admin will be logged in he may access frontend, other users will be redirected to a maintenance page.

Hope it helps.

Thanks.

1
  • I tried first extension you suggest Jun 7, 2017 at 4:49
1

Please try this ... add a custom module with this code:

app/code/local/My/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <My_Module>
            <version>0.0.1</version>
        </My_Module>
    </modules>
    <global>
        <models>
            <my_module>
                <class>My_Module_Model</class>
            </my_module>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_predispatch>
                <observers>
                    <check_admin_logged_in>
                        <class>my_module/observer</class>
                        <method>checkAdminIsLoggedIn</method>
                    </check_admin_logged_in>
                </observers>
            </controller_action_predispatch>
        </events>
    </frontend>
</config>

app/code/local/My/Module/Model/Observer.php

<?php

class My_Module_Model_Test extends Mage_Core_Model_Observer
{
    public function checkAdminIsLoggedIn(Varien_Event_Observer $observer)
    {
        if (!Mage::getSingleton('admin/session')->isLoggedIn()) {
            $page  = 'about-magento-demo-store'; 
            $controller = $observer->getControllerAction();
            $aliases = $controller->getRequest()->getAliases();
            if ($aliases['rewrite_request_path'] != $page) {
                $controller->getResponse()->setRedirect($controller->getRequest()->getBaseUrl() . '/' . $page);
                $controller->getResponse()->sendResponse();
                exit;
            }
        }
    }
}

Note: you have to create a new "CMS Page" and adjust following line for your URL key:

$page  = 'about-magento-demo-store'; 

You can also try this free extension: https://github.com/astorm/Magento_CrossAreaSessions

-1

1) You have to create an empty maintenance.flag file and upload it to the root folder of your site. After that your web site will have some message like:The server is temporarily unable to service...

2) open the index.php file and add this code on line 47:

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('69.65.23.100','2.2.2.2'); //list of IP that will have access to frontend

3) replace

if (file_exists($maintenanceFile)) {

With

if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

Nb: You can edit the message maintenance displayed in errors/default/503.phtml

4
  • NO, I want to set restriction for access front-end who is not logged-in to admin panel Jun 6, 2017 at 13:06
  • You said in title Only logged in admin should access to the frontend
    – PЯINCƎ
    Jun 6, 2017 at 13:08
  • Yes,exactly. Your code is only for specific IP Address Which i know already. Jun 6, 2017 at 13:11
  • before it was logged in and now is not logged in ;)
    – PЯINCƎ
    Jun 6, 2017 at 13:34

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.