Janaka
Janaka

Reputation: 408

Codeigniter redirect not working properly

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

Answers (4)

Anuj Tiwary
Anuj Tiwary

Reputation: 328

Its better to use base_url() functions with your controller name and function name

Upvotes: 0

Janaka
Janaka

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.error

Upvotes: -1

Satish Junghare
Satish Junghare

Reputation: 51

You can try this

redirect(base_url().'login');

Use base_url() brefore controller name 'login'

Upvotes: 1

Keval Rathi
Keval Rathi

Reputation: 986

Try this,

First option,

redirect('login', 'refresh');

Second option,

redirect('login');
exit;

Hope this helps you

Upvotes: 1

Related Questions