class Admin_Controller extends MY_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); $this->load->helper('url'); $this->load->helper('form'); $this->load->model('users_model'); } public function index() { $this->load->view('admin/dashboard'); } }
class Admin_Controller extends MY_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); $this->load->helper('url'); $this->load->helper('form'); $this->load->model('users_model'); $this->authenticate_user(); } private function authenticate_user() { if (!$this->session->userdata('admin_logged_in')) { redirect('admin/login'); } } }This example adds a new function called authenticate_user that checks whether the currently logged-in user is an admin. If the user is not authenticated, the function redirects them to the login page. Package library: CodeIgniter, Laravel.