|
(实在不会在这个论坛上传图片,太难操作了,后台都没有上传图片的点击按钮,只能复制粘贴代码了)
CI3底层system/libraries/Session/Session.php
1.第133行
// Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers
if (isset($_COOKIE[$this->_config['cookie_name']])
&& (
! is_string($_COOKIE[$this->_config['cookie_name']])
OR ! preg_match('#\A'.$this->_sid_regexp.'\z#', $_COOKIE[$this->_config['cookie_name']])
)
)
{
unset($_COOKIE[$this->_config['cookie_name']]);
}
session_start();
这段代码之前的操作是选择session driver,设置session配置,设置session_set_save_handler和设置session sid
为什么如果cookie存的$this->_config["cookie_name"],不匹配要设置的,会unset掉???
如果unset掉这个cookie,个人测试每次自定义handler,read函数读到的session_id都会改变
测试代码如下:(每次刷新页面都会var_dump出不一样的session_id)
<?php
class s implements SessionHandlerInterface{
public function open($save_path,$session_name)
{
return true;
}
public function read($session_id)
{
var_dump($session_id);
return "";
}
public function close()
{
return true;
}
public function write($session_id,$session_data)
{
return true;
}
public function destroy($session_id)
{
return true;
}
public function gc($maxlifetime)
{
return true;
}
}
ini_set("session.name","ci_test");
$_COOKIE["ci_test"] = 123213;
unset($_COOKIE["ci_test"]);
$class = new s;
session_set_save_handler(
$class
);
session_start();
1.第146行,安全校验session_regenerate
// Is session ID auto-regeneration configured? (ignoring ajax requests)
if ((empty($_SERVER['HTTP_X_REQUESTED_WITH']) OR strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest')
&& ($regenerate_time = config_item('sess_time_to_update')) > 0
)
{
if ( ! isset($_SESSION['__ci_last_regenerate']))
{
$_SESSION['__ci_last_regenerate'] = time();
}
elseif ($_SESSION['__ci_last_regenerate'] < (time() - $regenerate_time))
{
$this->sess_regenerate((bool) config_item('sess_regenerate_destroy'));
}
}
// Another work-around ... PHP doesn't seem to send the session cookie
// unless it is being currently created or regenerated
elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id())
{
setcookie(
$this->_config['cookie_name'],
session_id(),
(empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']),
$this->_config['cookie_path'],
$this->_config['cookie_domain'],
$this->_config['cookie_secure'],
TRUE
);
}
为什么如果是ajax操作,需要延长session的生存周期,而不是更新session_id????
求大神指教,万分感谢
|
|