Your authentication should be in the library:
This is an excerpt from the basic authentication codigniter script:
class Site_sentry { function Site_sentry() { $this->obj =& get_instance(); } function is_logged_in() { if ($this->obj->session) { if ($this->obj->session->userdata('session_logged_in')) { return TRUE; } else { return FALSE; } } else { return FALSE; } } function login_routine() {
This library is stored in the application / libraries under the file name, named after its class with the suffix .php.
Then you can add this to your autoload application / conig / config.php configuration file:
$autoload['libraries'] = array('database', 'site_sentry', 'session');
or load it manually in each controller:
$this->load->library('Site_sentry);
Then you can check your session from inside the controllers, for example:
class Class extends Controller{ function Class() { parent::Controller(); if( $this->site_sentry->is_logged_in() == FALSE){ redirect('managerlogin/'); } } }
Also check out this documentation page http://codeigniter.com/user_guide/libraries/sessions.html ; Of particular interest is saving a session to a database partition.
source share