简体   繁体   中英

Cakephp session is destroyed after redirect

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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