我知道这是2/3其他问题的重复,但我尝试了所提出的解决方案,但它们对我不起作用.我怀疑问题出在PHP.ini文件中,或者是服务器文件夹权限.
登录页面:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
//EDIT: forgot to copy paste this, but it is in my code
session_start();
if (isset($_POST['username']) && isset($_POST['password'])) {
//login function basically checks the posted username and password, then sets some
//session variables accordingly
login($_POST['username'], $_POST['password']);
}
if (isset($_SESSION['valid']) && $_SESSION['valid'] === true) {
header("Location: /HomePage/Home.php");
exit;
}
...
?>
Run Code Online (Sandbox Code Playgroud)
主页:
<?php
//EDIT: forgot to copy paste this, but it is in my code
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
if (!isset($_SESSION['valid']) || $_SESSION['valid'] !== true) {
header("Location: /index.php");
exit;
}
...
?>
Run Code Online (Sandbox Code Playgroud)
现在这里是奇怪的部分.根据firebug,当我输入有效的用户名和密码时,我被重定向到主页(如预测的那样),然后我被重定向回登录页面.我在主页上执行var_dump会话以进行检查,并且会话为空.
编辑2:当我用标题替换标题时
echo "Session is " . session_id() . "<br />";
Run Code Online (Sandbox Code Playgroud)
在登录页面上,session_id为空.那是问题吗?我如何解决它?
编辑:这是PHP ini文件的问题,感谢您的帮助.