Shahid H.
Shahid H.

Reputation: 82

Admin Access control not working

i'm trying to check if a user is logged in or not then i wan't to check if he is an admin or not if not then redirect it to login page but it ain't working

// Access control
        if (!$this->session->userdata('logged_in') ) {
            if(!$this->session->userdata('user_rol') == 'Administrator'){
            $this->session->set_flashdata('error_msg','Please login as an admin first!');

            redirect('admin/login');
            }
        } 

Any help please ??

Upvotes: 0

Views: 30

Answers (1)

Charlotte Dunois
Charlotte Dunois

Reputation: 4680

Actually your script does something different. The logic is if not logged in, it checks if the user rolle isn't admin.

I believe it should look like this, to do what you try to achieve.

if (!$this->session->userdata('logged_in') OR $this->session->userdata('user_rol') != 'Administrator') {
    $this->session->set_flashdata('error_msg','Please login as an admin first!');
    redirect('admin/login');
} 

Upvotes: 1

Related Questions