我正在开发一个网络应用程序。用户登录后,应存储一个$_SESSION
名为的变量。user
但是,当我稍后尝试访问它时,我无法访问它。
login.php 和 settings.php 都通过 AJAX 访问并显示在模式窗口中。
登录.php:
<?PHP
require("require/connect.php");
$errors = array();
$passed=FALSE;
if(isset($_POST['username']) && isset($_POST['password'])){
/* Check db, no output */
if($record->password != $password){ ?>
/* Output login fail message */
<?PHP }else if(intval($record->confirmed)!=1){ ?>
/* Output email not cofirmed message */
<?PHP }else{ ?>
$user = clone $record;
unset($user->password);
session_start();
$_SESSION['user']=$user;
print_r($_SESSION);
/*output success message*/
<?PHP };
}else{ /*output login form*/ } ?>
打印出来:
Array ( [user] => stdClass Object ( [id] => 11 [timestamp] => 2013-04-07 15:20:24 [username] => aakilfernandes [email] => email@gmail.com [salt] => 4d9b0fdc1d3241b9c9 [orders] => [karma] => 0 [stocks] => 0 [confirmation_code] => ed54er68d3d [confirmation_time] => 2013-04-07 15:20:24 [confirmed] => 1 ) )
设置.php
<?PHP
require("require/connect.php");
require("require/userdata.php");
/*other stuff*//
需要/userdata.php
<?PHP session_start();
print_r($_SESSION);
打印出来:
Array ( )