dongzizhi9903
dongzizhi9903
2017-03-22 07:01
浏览 19
已采纳

函数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);
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dto52236
    dto52236 2017-03-23 06:13
    已采纳

    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.

    点赞 评论
  • douyi1779
    douyi1779 2017-03-22 07:11

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

    点赞 评论
  • duanan1946
    duanan1946 2017-03-22 07:42

    Try this..

    redirect('Controller_name/function_name');
    
    点赞 评论

相关推荐