我遇到了会话变量的问题。自从我从 mysqli 切换到 PDO。它在 mysqli 上运行良好,但自从我切换到 PDO 后,这个问题就出现了。
我正在尝试登录,我有一个区域,我想确保用户只能看到,如果用户登录。登录工作正常,但是一旦我被引用到我的索引文件,我由于登录功能,什么也看不到。我可以看到 $_SESSION 变量被填满,但是一旦我重定向到另一个文件,$_SESSION 变量就会消失,我得到一个空数组:
Array
(
)
process_login.php
require_once('../inc/user.inc.php'); // here i have all my functions
$user = new User(); // New Instance of my User Class
$user -> sec_session(); // selfmade session function. I use start_session() in this function
if (isset($_POST['email'], $_POST['p'])) {
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$password = filter_var ($_POST['p'], FILTER_SANITIZE_STRING);
$login = $user -> login_user($email, $password);
if ($login) {
// Login sucessful
//print("<pre>".print_r($_SESSION,true)."</pre>"); //Here i get my $_SESSION variable printed out and it works. I see it is filled.
header('Location: ../index.php');
exit();
}
索引.php
<?php
$title = 'Index';
$currentPage = 'Dashboard';
include('php/head.php');
require_once('../inc/user.inc.php');
$user = new User();
$user -> sec_session(); // here i call my session function again. Note: session_start() is included in this function
print("<pre>".print_r($_SESSION,true)."</pre>"); //Now The Array is empty?!?
?>
user.inc.php - sec_session 函数
protected function sec_session() {
$session_name = 'sec_session_id';
$secure = SECURE;
$httponly = true;
if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
exit();
}
以上工作一切正常,但只会消失,当我登陆我的 index.php 并且我知道有一些东西时,但我不知道它是什么。
繁华开满天机