I've got a Problem with CodeIgniter 2.1.2 and stuck for hours try to solve it :-/
I know there are plenty(!) of threads about that, but i couldn't find a solution for my problem.
I want to load a method in my constructor to check if a user is logged in, so i tried this:
class my_class extends CI_Controller
{
public function __construct();
parent::__construct();
$this->check(); //doesn't work, endless redirection loop
}
"check()" is:
public function check()
{
if (! $this->session->userdata('logged_in'))
{
redirect('/login'); // tried with & without '/'
}
}
method "login()" looks like this:
public function login()
{
...
//do form validation stuff and on success:
if ($this->form_validation->run() == TRUE)
{
$this->session->set_userdata('logged_in', TRUE);
redirect('/entry');
}
//load login_view
}
method "entry()":
public function entry()
{
//$this->check();//Old (redundant) Version
//Authorized and Happy...
}
// some other methods, also call the check() method first
So my question is, why the calls in the methods works (but with much redundant calls) and the call in the constructor give me an endless loop? Do I miss something?? (I also didn't change stuff in the htaccess files..)
Thx in advance :-)