SESSION data is not passing along
I've had a rather out of the blue issue crop up with a project I've been working on for a while now. I setup the sessions portion of my code over a month ago and this morning, when I logged into a test account on my code, it seems my $_SESSION data is no longer passing through between pages.
The login script is working fine and successfully triggers header. But when I get to portalroom.php, print_r is generating "Array ( )". portalroom.php starts with session_start(). I've also confirmed that register_globals is off in my php.ini. At this point, I'm at a complete loss.
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"); }}}
(Edit) Here's the top of the code for portalroom.php:
session_start();
include('session.php');
include('functions.php');
include('sidebar.php');
include('scripts.php');
include('locationroom.php');
And because the actual code showing the $_SESSION data is being lost is on session.php, I've included the start of that:
// Are we logged in? If no - Kick 'em out
print_r($_SESSION);
if(!isset($_SESSION['user'])) { echo "we are here";
// header("location:login.php");
}
The relevant output from the code is: Array ( ) we are here
链接地址: http://www.djcxy.com/p/60246.html上一篇: 会话变量不再持久
下一篇: SESSION数据不会传递