如果我刷新页面,使用defaualt管理PHP的会话,会话总是一样的;但是如果我使用这个类将会话保存到DB中, 每次刷新页面时会话都会更改。
为什么呢?这是正常的吗?
class SessionPDO implements SessionHandlerInterface
{
private $db;
public function __construct($pdo)
{
$this->db = $pdo->getHandler();
session_set_save_handler($this, true);
$this->startSecureSession();
}
public function startSecureSession()
{
session_name("session_name");
session_set_cookie_params(
7200, //expiration - 0 is when browser closes
'/', //path over which cookies will be sent
null, //domain for cookie to operate
true, //Secure cookie HTTPS only
true //HTTP Only/No Javascript access
);
$this->setSecureConfig();
session_start();
}
public function setSecureConfig()
{
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1);
ini_set('session.hash_function', 'sha256');
ini_set('session.hash_bits_per_character', 6);
ini_set('session.entropy_file', '/dev/urandom');
ini_set('session.entropy_length', 1024);
ini_set('session.use_trans_sid', 0);
}
public function open($path, $sessionName)
{
// open code
}
public function close()
{
// close code;
}
public function read($sessionID)
{
// read code
}
public function write($sessionID, $data)
{
// write code
}
public function destroy($sessionID)
{
// destroy code
}
public function gc($max)
{
// gc code
}
}
答案 0 :(得分:0)
解决:我必须在0上设置session.cookie_secure,因为在本地主机上我没有使用安全连接