简体   繁体   English

重定向后Cakephp会话被破坏

[英]Cakephp session is destroyed after redirect

I'm currently on a MAMP install on my local machine testing a facebook application. 我目前正在本机上的MAMP安装中测试一个Facebook应用程序。 I suspect it is probably my MAMP configuration. 我怀疑这可能是我的MAMP配置。

In cake php in /user/login I set a session using 在/ user / login的蛋糕php中,我使用

$this->Session->write('Facebook.last_name',$user_profile['last_name']);
$this->redirect('/users/add');

then in /users/add I try and access all session informtaion 然后在/ users / add中,我尝试访问所有会话信息

print_r ($this->Session->read());

However the only session information that is returned is the following and not what I set. 但是,返回的唯一会话信息是以下内容,而不是我设置的内容。

Array ( [Config] => Array ( [userAgent] => 87a1f39ea78f3ab90174ff791710e6dc [time] => 1345915176 [countdown] => 10 )) 阵列([Config] =>阵列([userAgent] => 87a1f39ea78f3ab90174ff791710e6dc [time] => 1345915176 [countdown] => 10))

It may be that your session is not even being saved. 您的会话可能甚至没有保存。

What do you get when you write to the session then immediately debug it? 写入会话然后立即调试它会得到什么?

$this->Session->write('Facebook.last_name',$user_profile['last_name']);
debug($this->Session->read());
exit;

Check your core.php file for where your session variable is being saved as well. 检查您的core.php文件,以获取会话变量的保存位置。 I think it is arround line 136 in the config/core.php 我认为这是config / core.php中的第136行

You might forget initializing Session component in your controller file. 您可能会忘记在控制器文件中初始化Session组件。

Declare Session Component as follows in AppController, it will resolve issue for all the controllers. 在AppController中声明会话组件,如下所示,它将解决所有控制器的问题。 Or you can initialize it in your controller where you want to use Session 或者,您可以在要使用Session的控制器中对其进行初始化

var $components=array('Auth','Session'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM