我已经出现了一个相当突然出现的项目我现在已经工作了一段时间。我在一个月前设置了我的代码的会话部分,今天早上,当我在我的代码上登录测试帐户时,似乎我的$ _SESSION数据不再在页面之间传递。
登录脚本工作正常并成功触发标头。但是当我到达portalroom.php时,print_r正在生成" Array()"。 portalroom.php以session_start()开头。我还确认我的php.ini中的register_globals已关闭。在这一点上,我完全失去了。
session_start();
$dbcon = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_SESSION['user'])!="" ) {
header("Location: portalroom.php");
exit;
}
$error = false;
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($dbcon,$_POST['username']);
$mypassword = mysqli_real_escape_string($dbcon,$_POST['password']);
if(!$dbcon) {
die("Connection failed : " . mysqli_error());
$error = true;
}
if(!$error) {
$res=mysqli_query($dbcon, "SELECT userID,LoginName,Password FROM playerDB WHERE LoginName='$myusername'");
if(!$res) {
echo("Error:" . mysqli_error($dbcon));
exit();
}
$row=mysqli_fetch_array($res);
$count=mysqli_num_rows($res);
if( $count == 1 && password_verify($mypassword, $row['Password'])) {
$_SESSION['user'] = $row['userID'];
$_SESSION['last_activity'] = time();
$_SESSION['created'] = time();
header("Location: portalroom.php");
exit;
} else { echo("Incorrect Username/Password"); }}}
(编辑) 这是portalroom.php代码的顶部:
session_start();
include('session.php');
include('functions.php');
include('sidebar.php');
include('scripts.php');
include('locationroom.php');
因为显示$ _SESSION数据的实际代码正在session.php中丢失,所以我已经开始了:
// Are we logged in? If no - Kick 'em out
print_r($_SESSION);
if(!isset($_SESSION['user'])) { echo "we are here";
// header("location:login.php");
}
代码的相关输出是:Array()我们在这里