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

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

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

报告相同问题?

悬赏问题

  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥200 求能开发抖音自动回复卡片的软件
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。