函数codeigniter中的重定向问题

I have used a redirect url in my logout function, 1st time logout it works fine but subsequent requests after 1st time logout doesn't reaches logout function , rather it directly calls redirect url and why is it so, any explanation?

public function logout()
{
    $this->session->unset_userdata('user');
    $this->session->sess_destroy();
    redirect(base_url('user/def'));
}

after login session works fine in other pages

public function login(){
    if($user->name && $pwd){
        $data = array('id'=>$user->id,'username'=> $uname,'loggedin' => TRUE);
        $this->session->set_userdata('user',$data);
        $this->session->set_userdata($data);
    }
}

It was definitely the caching problem but for that I cleared the browser cache and it work with charm for 1st but later on same issue don't know whether the problem is caused by browser cache or whether codeigniter manages any cache for it so , added header for no-cache as mentioned below :

$this->output->set_header("Pragma: no-cache")

but still didn't work

finally cleared the issue by making the logout url dynamic i.e instead of calling

<a href='user/logout' >logout</a>

the logout url is called as :

<a href="<?php echo 'user/logout?i='.rand(); ?>" >logout</a>

www.example.com/user/logout?i=67543878

each time with a new i value the browser will treat this as new url to be called, which is how I solved the above mentioned issue.

If there is any other valid solution please let me know.

i think your redirect instruction code in function logout is wrong. it should be redirect ('login');

Try this..

redirect('Controller_name/function_name');