Cannot exit in CodeIgniter constructor
Posted
by
gzg
on Stack Overflow
See other posts from Stack Overflow
or by gzg
Published on 2012-10-27T16:56:46Z
Indexed on
2012/10/27
17:00 UTC
Read the original article
Hit count: 271
I'm basically trying a session control. If the user is logged in, it's ok to move on. But if he's not logged in, then it will show a log-in screen and then die. However, when I use die
or exit
in the constructor, it does not show the log-in screen; it immediately dies. The code is as following:
private $username = null;
private $mongoid = null;
private $neoid = null;
public function __construct(){
parent::__construct();
// session to global
$this->username = $this->session->userdata( 'username');
$this->mongoid = $this->session->userdata( 'mongoid');
$this->neoid = $this->session->userdata( 'neoid');
// check if user is logged in
if( $this->username == "" || empty( $this->username)){
$this->load->view( 'access/login');
die;
}
}
It shows the log-in page if die
is not written there, but with die
, it does not show. Why do I want to use die
? Because if I don't use, it moves on the index function and I don't want it to execute index function if the user is not logged in.
What is wrong here? What should I use to stop executing?
© Stack Overflow or respective owner