user3300065
user3300065

Reputation:

Make admin have access if on maintenance mode Codeigniter

I have a config item in application/config.php that if set to true will turn on maintenance mode and redirect to the URL.

But it blocks off every page. I use MY_Controller for the core maintenance. I would like to be able to have access to the controllers in my modules/admin/controllers/folders+

On MY_Controller.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends MX_Controller {
  public function __construct() {
      parent::__construct();
      if(!config_item('system_installed')) redirect('install');
   }
}

class Controller extends MY_Controller {
   public function __construct() {
      parent::__construct(); 
      if($this->config->item('system_maintenance') == TRUE) {
         redirect('maintenance');
         if($this->uri->segment('admin')) { // Should All ways has access

         }
      }
   }
}

On Application/Config.php

$config['system_maintenance] = TRUE; // Active

Example for Not Active And $config['system_maintenance] = FALSE; // Non Active

Upvotes: 1

Views: 737

Answers (1)

Dusan
Dusan

Reputation: 276

You can check for IP address in controllers __construct() and determine if it's admin user by IP. Maybe is better to check if client's web browser has some specific cookie, and if has, then it's super user and CI should ignore the maintenance mode restriction. Of course, check this in every class constructor you need to use during maintenance mode.

Upvotes: 1

Related Questions