我试图使用sessionHandler来写和读会话,所以我可以使用openssl_encrypt()和openssl_decrypt(),但当我在我的类中使用公共会话read()时,它会在方法下的vs红线中显示我,如果我使用sessionHandle类中存在的任何方法,它会显示我有什么问题。那么我如何扩展会话类并使用它的方法呢?
class SessionManager extends SessionHandler
{
private $sessionName = 'MYAPPSESSION';
private $sessionMaxLifetime = 0;
private $sessionSSL = false;
private $sessionHTTPOnly = true;
private $sessionPath = "/";
private $sessionDomain = ".mvcapp2.test";
private $sessionSavePath = SESSION_SAVE_PATH;
private $sessionCipherAlgo = "AES-128-ECB";
private $sessionCipherKey = "WQAS201VXZP@221D";
public function __construct()
{
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid', 0);
ini_set('session.save_handler', "files");
session_name($this->sessionName);
session_save_path($this->sessionSavePath);
session_set_cookie_params(
$this->sessionMaxLifetime,
$this->sessionPath,
$this->sessionDomain,
$this->sessionSSL,
$this->sessionHTTPOnly
);
session_set_save_handler($this, true);
}
public function read($id)
{
return openssl_decrypt(parent::read($id), $this->sessionCipherAlgo, $this->sessionCipherKey);
}
public function write($id, $data)
{
return parent::write($id, openssl_encrypt($data, $this->sessionCipherAlgo, $this->sessionCipherKey));
}
public function start()
{
if ("" === session_id()) {
return session_start();
}
}
}
1条答案
按热度按时间ssgvzors1#
尝试如下:
和