duanlinzhen7235 2013-12-02 07:52
浏览 92
已采纳

cookie未设置无法正常工作

I am using remember option in my login page.I think I am doing right but when in logout I just amn't able to unset the cookie variable.I am using CI but for cookie I am using native cookie.What am I doint wrong?My code: in login controller:

function index(){
if(isset($_COOKIE['remember_me'])){
  redirect('index');
}elseif($this->input->post()){
  $username = $this->input->post('username');
  $password = $this->input->post('password');
  $remember = $this->input->post('remember');
  if($remember){
      $time = time()+60*60*24*365;
      setcookie('remember_me', $username , $time);
  }
  $this->session->set_userdata('user_name', $user_name);
  $this->session->set_userdata('full_name', $full_name);
  $this->session->set_userdata('server', $server->exchange_server);
  redirect('index');
}else{
  $this->load->view('login');
}
}
function logout(){
 $this->session->unset_userdata('user_name');
 $this->session->unset_userdata('full_name');
 $this->session->unset_userdata('server');
 $data['login'] = 'Logout Successfully.';
 $data['class'] = 'success';
 $this->session->set_flashdata($data);
/* To unset cookie i tried following different approach but to no avail*/
setcookie('remember_me');
setcookie('remember_me', '', $time()-60*60*24*365);
setcookie('remember_me', false);
unset($_COOKIE['remember_me']);
 redirect('login');
}

but to no avail. I just can't unset cookie and when user who has checked remember me option trys to logout it's not happening. Any help/suggestion is welcome.Thanks

I don't know what is the problem but I used jquery plugin for cookie delete {https://github.com/carhartl/jquery-cookie}. I included jquery.cookie.js and then on logout click I deleted the cookie set as $.removeCookie('remember_me')

  • 写回答

3条回答 默认 最新

  • dousong1992 2013-12-05 12:14
    关注

    I don't know what is the problem but I used jquery plugin for cookie delete {https://github.com/carhartl/jquery-cookie}. I included jquery.cookie.js and then on logout click I deleted the cookie set as $.removeCookie('remember_me') and it's working fine.Thanks for the suggestions and help.

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

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端