I want to manage page redirection in codeigniter, I have two controllers:
- Logggedin
- login
When user try to access login
page while he is logged in, he is redirected to Loggedin
controller
function __construct()
{
parent::__construct();
$u = $this->session->userdata('username');
if(! isset($u))
{
redirect('loggedin');
}
}
And when he tries to access Loggedin
controller while he is not logged in, he should be redirected to login
controller
function __construct()
{
parent::__construct();
$u = $this->session->userdata('username');
if(isset($u))
{
redirect('login');
}
}
But when I press logout button, it has to redirect to Login
controller, but he still remains on Logggedin
controller.
function logout()
{
$this->session->sess_destroy();
redirect('login');
}
What could be the problem in code?