Fixing multiple Set-Cookie request problem in Cakephp ( 59 )

 

 

I just noticed last weekend that on firebug my websites are showing multiple times Set-Cookie request in the header. so, I start to search what problem is and found few topics on www.stackoverflow.com. As I see, many Cakephp projects are using in config file Session.start as true but seems that exactly this is the problem, at least in Cakephp 1.2.X.
The solution is to set in config/core.php this Session.start as false:


Configure::write('Session.start', false);

After this step, the function(s) with checks the user session ( like login ) has to cotain:

$this->Session->activate('/'); 
$this->Session->start();

On views, the header.ctp template or templates where you use session must have:

$session->activate('/'); 

On logout function you can use also:

$this->Session->activate('/'); 
$this->Session->start();

and
	
$this->Session->destroy();

After these changes the website runs faster than before.