Cakephp session is destroyed after redirect

2019-09-07 11:00发布

I'm currently on a MAMP install on my local machine testing a facebook application. I suspect it is probably my MAMP configuration.

In cake php in /user/login I set a session using

$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

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 ))

2条回答
倾城 Initia
2楼-- · 2019-09-07 11:28

You might forget initializing Session component in your controller file.

Declare Session Component as follows in AppController, it will resolve issue for all the controllers. Or you can initialize it in your controller where you want to use Session

var $components=array('Auth','Session'); 
查看更多
beautiful°
3楼-- · 2019-09-07 11:29

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. I think it is arround line 136 in the config/core.php

查看更多
登录 后发表回答