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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私