Cakephp - session variable keeps acting strange
For reasons that elude me, the session variable containing the client's name will show up briefly and then disappear.
In app_controller.php: beforeFilter ()
if (isset($_SESSION['customer_name']) == false ||
strlen($_SESSION['customer_name']) == 0)
{
$customer = $this->Customer->read(null, $auth['User']['customer_id']);
$name = $customer['Customer']['fname'] . " " . $customer['Customer']['lname'];
$this->Session->write('customer_name', $name);
$this->set('name', $this->Session->read('customer_name'));
}
else
{
$this->set('name', $this->Session->read('customer_name'));
}
I tried the validation options to check if a session is established like
if ($this->Session->check('customer_name') == false)
Everything behaves in the same strange way that it will appear in the view for a while and then disappear. Will not revert to close browser or login again. Random small changes to this code seem to bring it to life for a short time.
a source to share
Use $ this-> Session-> read () instead of direct calls to $ _SESSION, as cakephp can store the session somewhere else, which is where native PHP expects it.
Also, I really don't understand what you mean by "fade out for a while", if you stay on the same page and just keep updating, does it show random display / fade out?
Closing your browser could very well be the reason your session gets destroyed, are you also experiencing this behavior across browsers?
What are your Session.*
sessings in app / config / core.php?
a source to share
Not sure what the problem is, but I would start by removing the $ _SESSION calls. I would also change
strlen($_SESSION['customer_name']) == 0
to
empty($_SESSION['customer_name'])
The only thing I can think of is to lower the security level in /config/core.php, maybe you will completely lose the session?
a source to share
Please note that sometimes FireFox extensions can cause a session reset. Each time the User-Agent changes, the session is reset.
I recently ran into this issue using a FireBug extension called FirePHP:
http://blog.kevburnsjr.com/cakephp-session-error-user-agent-must-be-consistent
a source to share