我想弄清楚会话如何在Codeigniter中工作。阅读在线手册,我看到以下内容:
如果会话数据不存在(或者已过期),将创建一个新会话并保存在cookie中。如果会话确实存在,则会更新其信息并更新cookie。每次更新时,都会重新生成session_id。
和
注意:会话cookie默认每五分钟更新一次,以减少处理器负载。如果您反复重新加载页面,您会注意到“上次活动”时间仅在自上次写入cookie后经过五分钟或更长时间后才会更新。可以通过更改system / config / config.php文件中的$ config ['sess_time_to_update']行来配置此时间。
问题:
任何澄清都会有所帮助!
答案 0 :(得分:2)
是的,是关于存储在cookie中的会话ID。每5分钟重新生成一次。当需要重新生成时,首先它将获取当前会话数据,然后将其分配给新的会话ID。
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;