如何在 CakePHP 之外访问 loggedInUser 的 SESSION 2.x
How to access SESSION of loggedInUser outside CakePHP 2.x
我需要知道用户是否已登录并需要访问他在 CakePHP 之外但在同一域中的信息。
我试过以下代码
session_start();
session_name('CAKEPHP');
if(isset($_COOKIE['CAKEPHP'])){
session_id($_COOKIE['CAKEPHP']);
echo "isset<br/>";
var_dump($_SESSION);
}
echo "user :".$_SESSION['userCakeUser']['email'];
我有以下输出:
isset
array(1) {
["userCakeUser"]=> object(__PHP_Incomplete_Class)#1 (7)
{ ["__PHP_Incomplete_Class_Name"]=> string(12) "loggedInUser"
["email"]=> string(17) "a@a.net"<
["hash_pw"]=> string(65) "dsfsdfsdfsdfsdfsdfddsfsdfsdfsdf"
["user_id"]=> int(4) ["title"]=> string(10) "New Member"
["displayname"]=> string(5) "Toto"
["username"]=> string(5) "Toto"
}
}
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array on line 15
例如,请告诉我如何访问电子邮件。
错误消息为您提供了有关问题的足够信息:
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array on line 15
您正在处理的是一个对象。尝试:
echo "user :".$_SESSION['userCakeUser']->email;
谢谢@Inigo Flores,
好多了,但我有以下错误:
Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "loggedInUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition on line 16`
所以我已经包含了这个 class :
include("path_to_cake_php/models/class.user.php" )
我需要知道用户是否已登录并需要访问他在 CakePHP 之外但在同一域中的信息。
我试过以下代码
session_start();
session_name('CAKEPHP');
if(isset($_COOKIE['CAKEPHP'])){
session_id($_COOKIE['CAKEPHP']);
echo "isset<br/>";
var_dump($_SESSION);
}
echo "user :".$_SESSION['userCakeUser']['email'];
我有以下输出:
isset
array(1) {
["userCakeUser"]=> object(__PHP_Incomplete_Class)#1 (7)
{ ["__PHP_Incomplete_Class_Name"]=> string(12) "loggedInUser"
["email"]=> string(17) "a@a.net"<
["hash_pw"]=> string(65) "dsfsdfsdfsdfsdfsdfddsfsdfsdfsdf"
["user_id"]=> int(4) ["title"]=> string(10) "New Member"
["displayname"]=> string(5) "Toto"
["username"]=> string(5) "Toto"
}
}
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array on line 15
例如,请告诉我如何访问电子邮件。
错误消息为您提供了有关问题的足够信息:
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array on line 15
您正在处理的是一个对象。尝试:
echo "user :".$_SESSION['userCakeUser']->email;
谢谢@Inigo Flores,
好多了,但我有以下错误:
Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "loggedInUser" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition on line 16`
所以我已经包含了这个 class :
include("path_to_cake_php/models/class.user.php" )