I want to check the session; if it exits it goes to my web site, otherwise redirecting to "login" page; here is my controller:
function __construct() {
parent::__construct();
$this->is_logged_in();
}
public function index($failed=FALSE) {
$data['main_content'] = 'login_view';
$data['failed_validation'] = $failed;
$this->load->view('includes/template', $data);
}
public function is_logged_in() {
if ($this->session->userdata('f_name') != null) {
return;
} else {
$this->index();
//die()// This one does not help either
}
}
public function display_site() {
$data['main_content'] = 'site_view';
$this->load->view('includes/template', $data);
}
This is the version after suggestion(but still the same problem!):
Controller:
function __construct() {
parent::__construct();
$this->load->model('user_model');
if ($this->user_model->is_logged_in() == FALSE) {
$this->index();
}
}
public function index($failed=FALSE) {
$data['main_content'] = 'login_view';
$data['failed_validation'] = $failed;
$this->load->view('includes/template', $data);
}
public function login() {
$data['main_content'] = 'login_view';
$data['failed_validation'] = FALSE;
$this->load->view('includes/template', $data);
}
Model:
public function is_logged_in()
{
return ($this->session->userdata('is_logged_in') );
}
Thats fine but when the user goes to logs in page, it shows both login page and my website main page! In other hand even if I die in (see the comment in my code) it does not help, it gives me a blank page!
Thanks