Ich habe eine verarbeite_formular Seite wie folgt aus:PHP-Sitzung nach Umleitung verloren - versucht, alles von Google und Stackoverflow
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start(); // Our custom secure way of starting a PHP session.
if (isset($_POST['email'], $_POST['p'])) {
$email = $_POST['email'];
$password = $_POST['p']; // The hashed password.
if (login($email, $password, $mysqli) == true) {
// Login success
header('Location: test.php');
die();
} else {
// Login failed
header('Location: login.php?error=1');
exit;
}
} else {
// The correct POST variables were not sent to this page.
echo 'Invalid Request';
}
?>
Wenn ich ein tun print_r($_SESSION)
nach //Login success
ich habe alle $_SESSION
OK. Nach der Weiterleitung ist es weg. Ich habe fast alle versucht (exit;
exit();
die();
nach header()
und immer noch nichts setzen
Mein Test PHP-Seite.
<?php
include_once 'includes/functions.php';
sec_session_start();
print_r($_SESSION);
und die sec_session_start() Funktion:
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = true;
// This stops JavaScript being able to access the session id.
$httponly = true;
// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}
// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
// Sets the session name to the one set above.
session_name($session_name);
session_start(); // Start the PHP session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
Ich habe $ _SESSION Parameter in login
Funktion
Ich weiß nicht, was ich tun soll bug dies.
php.ini SESSION Parameter:
session.save_path="C:\xampp\tmp"
session.use_strict_mode=0
session.use_cookies=1
session.use_only_cookies=1
session.name=PHPSESSID
session.cookie_lifetime=0
session.cookie_path=/
session.cache_expire=180
session.save_handler=files
Nach Zeile für Zeile aus dem sec_session_start()
Entfernen ich es diese durch Entfernen aus arbeiten:
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
**$secure**,
$httponly);
Jetzt kann ich $_SESSION
Variable in test.php erhalten .
Update # 2: nur Einstellung $secure = false
funktioniert.
zeigen Sie Apache Fehlerprotokoll? – Naumov
versuchen, "ob_start();" am Anfang der Seite –
@RanjeetSingh warum? – Naumov