我创建了一个登录屏幕,用于检查密码是否正确。
提交登录表单后,我会看到包含以下行的process.php:
if (password_verify($passwordPost, $passwordDB)) {
$_SESSION['loged_in'] = true;
} else {
$_SESSION['loged_in'] = false;
}
# when I do a print_r on $_SESSION['loged_in'] it results true
header('Location: ../../admin/index.php');
检查会话的索引页面(../../ admin / index.php)
<?php
session_start();
# when I do a print_r on $_SESSION['loged_in'] here, it results false
if ($_SESSION['loged_in'] == false) {
include(PATH_COMPONENTS.'login/index.php');
}
?>
这怎么可能?
答案 0 :(得分:1)
你必须在每个文件中启动会话!像这样:
session_start(); //most times at the top of every file
是的,您必须在使用它的每个文件中启动会话!
另外,对于错误报告,请使用:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>