这是我的登录页面的代码,其中登录脚本检查用户的真实性,然后使用标题功能重定向到收件箱页面。
<?php
session_start();
include_once('config.php');
$user=htmlentities(stripslashes($_POST['username']));
$password=htmlentities(stripslashes($_POST['password']));
// Some query processing on database
if(($id_user_fetched<=$id_max_fetched) && ($id_user_fetched!=0)){
$_SESSION['loggedIn'] = 'yes';
header("Location:http://xyz/inbox.php?u=$id_user_fetched");
//echo 'Login Successful';
}else{
echo 'Invalid Login';
echo'<br /> <a href="index.html">Click here to try again</a>';
}
}else{
echo mysqli_error("Login Credentials Incorrect!");
}
?>
inbox.php 页面如下所示:
<?php
session_start();
echo 'SESSION ='.$_SESSION['loggedIn'];
if($_SESSION['loggedIn'] != 'yes'){
echo $message = 'you must log in to see this page.';
//header('location:login.php');
}
//REST OF THE CODE
?>
现在使用上面的代码,inbox.php 总是显示输出:SESSION=you must login to see this page。这意味着会话变量未设置或 inbox.php 无法检索会话变量。我哪里错了?