Reputation: 47
I have one header file for the home page and the login page in that header. I wrote this code on top of it
<?php
if ($this->session->userdata('logged_in')==true ){
redirect('home','refresh');
}else{
redirect('home/login','refresh');
}
?>
but it keeps redirecting me to the same page and it shows nothing
Upvotes: 0
Views: 67
Reputation: 831
Try this
put these line in every controller's __construct
function
if ($this->session->userdata('logged_in') !=true) {
if ($this->router->fetch_class() != 'home' && $this->router->fetch_method() != "login") {
redirect("home/login");
}
}
Upvotes: 1
Reputation: 649
Remove the else redirect on login page, its already in login page
if ($this->session->userdata('logged_in')==true ){
redirect('home');
}
except login, you can redirect the page :)
to differ the login page and home page just send the
$this->data["pagename"]="login"; in login function and
$this->data["pagename"]="home"; in home function
and in header
if ($this->session->userdata('logged_in')==true ){
redirect('home');
} else {
if($pagename!="login")
{
redirect('home/login');
}
}
Upvotes: 1
Reputation: 19
<?php
if ($this->session->userdata('logged_in')!==FALSE){
redirect('home','refresh');
}
else{
redirect('home/login','refresh');
}
?>
try the above code..
Upvotes: 1
Reputation: 379
$user_logged_in=$this->session->userdata('logged_in');
if (!$user_logged_in)
{
redirect('home/login','refresh');
}else{
redirect('home','refresh');
}
Upvotes: 1