I have a problem in login application in codeigniter , the problem is like this:

I create MY\_Controller, like this:

```
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

    public function __construct(){

        parent::__construct();

    }

}

```

Then I extended it on my library that i created, this is my "Petugas\_Controller" library:

```
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Petugas_Controller extends MY_Controller {

    public function __construct(){

        parent::__construct();
        $this->load->model('petugas_m');

    } // end contructor.

    public function check(){

        if ($this->uri->uri_string() !== 'index' && ! $this->petugas_m->is_logged_in() == TRUE){     
            redirect('admin/petugas/index');
        }
    }

}

```

I'm using that library to be used in my "Petugas" controller, like this:

```
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Petugas extends MY_Controller {

    public function __construct(){

        parent::__construct();
        $this->load->library('petugas_controller');
        $CI = &get_instance();
        $CI->check();

    }

    public function index(){

        echo "You have to login";
    }

    public function dashboard(){

        echo "Welcome to dashboard";

    }

}

```

In "Petugas\_Controller" library, I loaded model that is called "Petugas\_m", here is the model :

```
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Petugas_m extends CI_Model {

    public function __construct(){

        parent::__construct();

    }

    public function is_logged_in(){

        return FALSE;
    }
}

```

That's all what i was trying, and my problem is I want to check if username is logged or not, by doing $this->check() in "Petugas\_library" that loads "Petugas\_m" model, i could see an dashboard echo if the "check" method in "Petugas\_m" is set to TRUE but it's always redirect me a loop if it FALSE.

I was searching for tutorials and still have this crazy problem :( ,
Thank in advance, and sorry for my bad english.