CodeIgniter 2.1.0的会话库中是否有任何已知的错误?为什么我被开除了


Is there any known bug in the session library of CodeIgniter 2.1.0? Why do I get kicked out?

我正在制作一个使用CodeIgniter 2.1.0创建的网站。

我注意到有时当我重新加载一个页面几次或打开几个页面非常快,或者当我在代码中有一个错误(这些错误与会话无关),我得到登出。

这个网站正在使用一个名为Ion_authand的库进行标识:

public function logged_in()
{
  $identity = $this->ci->config->item('identity', 'ion_auth');
  return (bool) $this->ci->session->userdata($identity);
}

有什么bug或者什么我应该知道的吗?

$config['sess_cookie_name']  = 'cisession';
$config['sess_expiration']  = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name']  = 'cisession';
$config['sess_match_ip']  = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

在这个网站上,会话几乎每一页都有更新。

结果如下:

CodeIgniter的会话库中有一个错误,它会在快速请求时破坏会话。

在这里你可以找到更多关于这个bug的信息:

https://github.com/EllisLab/CodeIgniter/issues/154

这个错误在最新的稳定版本2.1.3中仍然存在。

我已经通过用GitHub的CI3-DEV替换我的会话库来修复这个问题:

https://github.com/EllisLab/CodeIgniter/blob/b211adee89f5fd2192051e9c0826146bd150f469/system/libraries/Session.php

并在我的配置中放置一个长sess_expiration和sess_time_to_update…我的是86400和86500。

CodeIgniter将会话数据保存在cookie中。如果会话数据中有任何特殊字符可以取消cookie设置,会话也会被销毁。

它也产生了一些更多的大小限制问题。Cookie可以根据浏览器保存有限大小的数据。如果您尝试在CodeIgniter会话中存储更多数据,并且CodeIgniter试图将其保存在cookie中,则它可能不会保存超过该限制。

由于cookie是通过网络发送的,它不必要地增加了网络上的流量。所有的会话数据不应该保存在cookie中。

最好使用本机会话库。它使用PHP的本地会话。

https://github.com/EllisLab/CodeIgniter/wiki/Native-session

https://github.com/EllisLab/CodeIgniter/wiki/PHPSession

你可以比较两者

关于CodeIgniter如何存储会话数据,请参考CodeIgniter会话文档。

https://www.codeigniter.com/user_guide/libraries/sessions.html