Reputation: 408
In my class constructor the redirect function working properly
public function __construct(){
parent::__construct();
$session_data = $this->session->userdata('logged_in');
if( $session_data['type']!='admin' ){
//this redirect working properly
redirect('login');
}
$this->load->model('functions');
$this->load->model('user');
}
But inside my one of other function in same class, that not working
public function logout(){
$this->session->unset_userdata('logged_in');
$this->session->sess_destroy();
//this redirect not working
redirect('login');
}
I tried out several ways, but could not make it work. In my autoload I have loaded url helper properly. $autoload['helper'] = array('url','form'); So whats wrong with this.
Upvotes: 0
Views: 1137
Reputation: 328
Its better to use base_url() functions with your controller name and function name
Upvotes: 0
Reputation: 408
Well, the problem is there are some spaces after the PHP end tag in my user model I used in this controller. So I removed those spaces then redirect function worked properly. Herewith I've attached a screenshot got from Sublime editor. Thanks everyone who tried for this.
Upvotes: -1
Reputation: 51
You can try this
redirect(base_url().'login');
Use base_url() brefore controller name 'login'
Upvotes: 1
Reputation: 986
Try this,
First option,
redirect('login', 'refresh');
Second option,
redirect('login');
exit;
Hope this helps you
Upvotes: 1