我用它從數據庫中保存和讀取會話數據的自定義會話處理程序: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