Ich habe einen lokalen Webserver eingerichtet und ein Projekt eingefügt, an dem ich gearbeitet habe (der Code funktionierte bereits). Das Problem, das ich sehe, ist, dass session_start()
die bereits erstellten Sitzungen ignoriert und neue erstellt (ich kann eine neue Datei sehen, wenn ich auf einen Link klicke oder die Seite aktualisiere), obwohl die Sitzungsvariablen in die Datei geschrieben werden .php session_start() ignoriert bereits erstellte Sitzungen
Der Sitzungsordner gehört dem HTTP-Benutzer (der Standard in der php-fpm-Konfiguration).
Dies ist die Session Config aus der php.ini:
session.save_handler = files
session.save_path = "/srv/http/sessions"
session.use_strict_mode = 1
session.use_cookies = 1
session.cookie_secure = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path =/
session.cookie_domain =
session.cookie_httponly = 1
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
Wer weiß, was los ist?
Dies ist die Funktion, die die Sitzung beginnt:
public static function sec_session_start() {
if (ini_set('session.use_only_cookies', 1) === FALSE) {
$session_error = 'Error: Cannot create new user session.';
return $session_error;
}
else {
$session_name = 'session_id';
$domain = 'domain.com';
$secure = TRUE;
$httpOnly = TRUE; // prevents cookie theft
// Get the current cookies params.
$cookieParams = session_get_cookie_params();
// Set the current cookies params.
session_set_cookie_params($cookieParams['lifetime'], $cookieParams['path'], $domain, $secure, $httpOnly);
// Sets the session name to the one set above.
session_name($session_name);
session_start(); // Start the PHP session
if (!isset($_SESSION['CREATED'])) {
$_SESSION['CREATED'] = time();
} else if ((time() - $_SESSION['CREATED']) > 1800) {
// session started more than 30 minutes ago
session_regenerate_id(TRUE); // change session ID for the current session and invalidate old session ID
$_SESSION['CREATED'] = time(); // update creation time
}
/*
$hasExpired = FALSE;
if (isset($_SESSION['staff_id'], $_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY']) > 9999) { // 300 (5 mins)
// last request was more than 5 minutes ago
$_SESSION = array(); // unset $_SESSION variable for the run-time
$params = session_get_cookie_params(); // Get session parameters
setcookie(session_name(), // Delete the actual cookie
'',
time() - 3600,
$params["path"],
$params["domain"],
$params["secure"],
$params["httponly"]);
session_destroy(); // destroy session data in storage
$hasExpired = TRUE; // now we know the user has lost his session for inactivity
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp*/
}
//return $hasExpired;
}
Zeigen Sie den Code ... – AbraCadaver
Sicher, aber ich sagte bereits, dass der Code im alten Hosting funktioniert und es ist ziemlich generisch. –
Was ist die PHP-Version? –