【发布时间】:2011-10-28 08:04:30
【问题描述】:
Class User{
public $id;
public $username;
public $password;
public $email;
public $steam;
public $donator;
public $active;
public function __construct($username, $email, $password, $id, $active, $donator, $steam){
$this->id = $id;
$this->username = $username;
$this->password = $password;
$this->email = $email;
$this->steam = $steam;
$this->donator = $donator;
$this->active = $active;
}}
是我的课(简体)
以下是我的代码:
$_SESSION['loggedIn'] = $user;
$user 是 User 的类实例
现在这就是 print_r($_SESSION['loggedIn']) 向我展示的内容:
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => User
[id] => 22
[username] => xxxx
[password] => xxxx
[email] => xxxx
[steam] => 1234567
[donator] => 0
[active] => 1
)
其中 xxxx 是正确的值。
但是当我尝试从我的会话中检索数据时。像这样: "$_SESSION['loggedIn']->username" 它返回一个空值给我。
【问题讨论】:
-
我不会那样做的。例如,如果用户在另一台计算机上登录时使用另一台计算机更改他的电子邮件,您最终可能会得到旧数据。或者,如果您从数据库中删除用户,您的应用程序仍会认为该用户存在。相反,我会在会话中只存储用户 ID,并在处理来自用户的请求时从数据库中检索其余信息。