Welcome Guest, Not a member yet? Register   Sign In
Is this a good way to protect a page (using ion_auth)?
#1

[eluser]dallen33[/eluser]
Basically, if you're not logged in, you get redirected to the login page. If you're logged in but not an admin, you get redirected to the home page with a message. It works, but just wanting to make sure this is a good way of doing it or if I should be doing it another way.

Code:
public function index()
{
    if ( ! $this->ion_auth->logged_in()):
    redirect('auth/login');
    elseif ( ! $this->ion_auth->is_admin()):
        $this->session->set_flashdata('message', 'You must be an admin to view this page');
        redirect('home');
    endif;
    
    // Rest of the code for admin functions go here
}




Theme © iAndrew 2016 - Forum software by © MyBB