Welcome Guest, Not a member yet? Register   Sign In
Stupid redirect question
#1

[eluser]victorche[/eluser]
Really sorry for this stupid question, but i am totally blocked today...
I have a simple logic, which makes all non logged users (guests) to be redirected to /login
And i can make the check in every single controller, but i prefer it in one place only, in my case MY_Controller.php:
Code:
class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        if (!$this->auth->logged_in())
        {
            redirect('/login', 'refresh');
        }
    }
}
Makes sence, right?
And in login.php I have a simple piece of code:
Code:
class Login extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->view('login.tpl.php');
    }
}
The result is ... continius reloadin of /login
Any ideas, please?
#2

[eluser]Twisted1919[/eluser]
Code:
class MY_Controller extends CI_Controller
{
    protected $dont_check = array();

    function __construct()
    {
        parent::__construct();
        $this->dont_check = array('login');
        $segment = $this->uri->segment(1);//
        if(!in_array($segment,$this->dont_check))
        {
          if (!$this->auth->logged_in())
          {
            redirect('login');
          }        
        }

    }
}




Theme © iAndrew 2016 - Forum software by © MyBB