我用它从数据库中保存和读取会话数据的自定义会话处理程序:PHP会话未设置随机
class c_session implements SessionHandlerInterface {
private $db; // Database
// Constructor
public function __construct($database){
$this->db = $database;
session_set_save_handler(
array($this, 'open'),
array($this, 'close'),
array($this, 'read'),
array($this, 'write'),
array($this, 'destroy'),
array($this, 'gc')
);
register_shutdown_function('session_write_close');
}
// Custom made session start
public function start_session() {
global $globals; // Included in config.php
// Make sure the session cookie is not accessible via javascript.
$httponly = true;
// Force the session to only use cookies, not URL variables.
ini_set('session.use_only_cookies', 1);
// Get session cookie parameters and set the parameters
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $globals['https'], $httponly);
// Change the session name
session_name($globals['session_name']);
// Now we can start the session
session_start();
}
...
在每一个网页,我读来检查会话如果用户已经签署:
function signin_check($db, $session) {
global $globals; // Included in config.php
$session->start_session();
try {
// Check if all session variables are set
if(isset($_SESSION['A'], $_SESSION['B'])) {
...
如果她没有,她将被注销。
变量$_SESSION['A']
和$_SESSION['B']
在登录页面设置。
的系统协同工作的时候完全99%,但有时候,改变网页时,它随机将您注销。这是因为无论是$_SESSION['A']
和$_SESSION['B']
都没有(已知)原因未设置。
为什么以及如何防止这些注销?
乍一看,这听起来像你的会议超时。如果你可以检查你的php.ini设置,你能看到为session.cookie_lifetime和session.gc_maxlifetime设置了什么吗? – Raf