Not allowing access to home page when have correct role id

34 views Asked by At

When my maintenance mode is on.

I would like to be able to still view the home page when maintenance mode is on.

But only if the member session role_id = 1

Currently does not let me view the home page at all even though my session role_id == 1 keeps redirecting to maintenance page

Question: How can I make sure can view home page if maintenance mode is active but if session role id == '1'

public function maintenance_mode() {

    $maintenance_mode = $this->is_maintenance();

    if ($maintenance_mode) {

        if ($this->session->userdata('role_id') == '1') {
            return true;
        } else {
            $route = $this->uri->segment(1) .'/'. $this->uri->segment(2);

            $ignore = array('common/maintenance');

            if (!in_array($route, $ignore)) {
                redirect(base_url('common/maintenance'));
            }
        }
    } 
}

public function is_maintenance() {
    $query = $this->db->where('item', 'maintenance_mode')->get('settings')->row('value');
    return $query;
}
1

There are 1 answers

0
AudioBubble On

Solution

The code in my question was fine. I found the issue. it was creating the sessions twice one for www.example.co.nz and one for example.co.nz

I need to add cookie domain

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '.example.co.nz';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;