Take the 2-minute tour ×

i want to give access only to the authorized users so i wrote the authentication code in the construct method here is my code

class cp extends CI_Controller {

    public function __construct(){

    public function this_mustbe_admin()

        $md = $this->m_cp->is_admin();
         return $md;


    function login()


but i get error

The page isn't redirecting properly

if i remove this_mustbe_admin method from construct and put it on the other controllers it works fine

function do_stuff(){

   // do stuff 


but this way i have to write it in each and every one of my methods

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You doing circular redirection. An imaginary stack trace:

  1. http request to /cp/
  2. __construct()
  3. this->this_mustbe_admin() -> redirect to /cp/login
  4. http request to /cp/login
  5. __construct()
  6. this->this_mustbe_admin() -> GOTO 3.

You will have to check what method you are trying to execute in your __construct before doing the redirection generating command.

if (!$this->router->method != 'login') {
share|improve this answer

Try to write like this


i hope may it wrks....or simply give


because i got when i used like this

share|improve this answer

Your Answer


