[英]How Sessions in Codeigniter Work
I am trying to figure out how sessions work in Codeigniter. 我想弄清楚会话如何在Codeigniter中工作。 Reading the online manual, I see the following:
阅读在线手册,我看到以下内容:
If sessions data does not exist (or if it has expired) a new session will be created and saved in the cookie.
如果会话数据不存在(或者它已过期),则会创建一个新会话并将其保存在cookie中。 If a session does exist, its information will be updated and the cookie will be updated.
如果会话确实存在,则会更新其信息并更新cookie。 With each update, the session_id will be regenerated.
每次更新时,都会重新生成session_id。
and 和
Note: Session cookies are only updated every five minutes by default to reduce processor load.
注意:默认情况下,会话cookie每五分钟更新一次,以减少处理器负载。 If you repeatedly reload a page you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time the cookie was written.
如果您反复重新加载页面,您会注意到“上次活动”时间仅在自上次写入cookie后经过五分钟或更长时间后才会更新。 This time is configurable by changing the $config['sess_time_to_update'] line in your system/config/config.php file.
可以通过更改system / config / config.php文件中的$ config ['sess_time_to_update']行来配置此时间。
Question : 问题 :
Any clarifications will help! 任何澄清都会有所帮助!
Yes, is about the session id stored in the cookie. 是的,是关于存储在cookie中的会话ID。 This is regenerated every 5 minutes.
每5分钟重新生成一次。 And when it's time to regenerate, first it will get current session data and than assign it to the new session id.
当需要重新生成时,首先它将获取当前会话数据,然后将其分配给新的会话ID。
code from CI session library, function sess_update(): CI会话库中的代码,函数sess_update():
// Save the old session id so we know which record to
// update in the database if we need it
$old_sessid = $this->userdata['session_id'];
$new_sessid = '';
while (strlen($new_sessid) < 32)
{
$new_sessid .= mt_rand(0, mt_getrandmax());
}
// To make the session ID even more secure we'll combine it with the user's IP
$new_sessid .= $this->CI->input->ip_address();
// Turn it into a hash
$new_sessid = md5(uniqid($new_sessid, TRUE));
// Update the session data in the session data array
$this->userdata['session_id'] = $new_sessid;
$this->userdata['last_activity'] = $this->now;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.