dongyouzhui1969 2014-05-25 12:42
浏览 156
已采纳

Codeigniter - 更改“cookie_domain”后无法重新登录

My Codeigniter's sessions used the default value

$config['cookie_domain'] = "";

But now I need to be able to use CodeIgniter's sessions from domain.com on

  • subdomain1.domain.com
  • subdomain2.domain.com

So I saw in the codeigniter manual that you can set

$config['cookie_domain'] = ".domain.com";

And the extra dot will make all the ci_sessions shared by the domain and subdomains. This works perfect!

However, it is impossible to log back in the system after changing cookie_domain from "" to ".domain.com" unless I manually delete the cookie ci_session in the chrome settings.

I can't ask all the users to delete their cookies so I need to find a way. I tried all of this:

delete_cookie('ci_session');
setcookie('ci_session', '', time()-3600);
$this->session->sess_destroy();
unset($this->session->userdata);
$this->session->unset_userdata( <array with all the session keys> )
foreach ($_COOKIE as $key=>$cookie)
setcookie($key, '', time() - 9999999);

Some useful info maybe, sess_expiration is set to 2 weeks, this is why I tried a huge number in the setcookie function:

$config['sess_expiration']      = 1209600; // 2 weeks

Also, after all these commands to make the cookie expired. Chrome still says that the ci_session cookie expires in 2 weeks. It's as if it was completely oblivious to the function setcookie

  • 写回答

1条回答 默认 最新

  • duanben4771 2014-05-25 12:47
    关注

    Change your current $config[sess_cookie_name] from ci_session - to something else like new_cookie

    Then the browser will look for the new_cookie name, which wont exist - and thus force a new cookie on all your users

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配