MediaTemple with CakePhp Session Lost during Refresh
Problem:
I just came across as strange problem with using CakePhp on MediaTemple. This is my first CakePhp application on MediaTemple but I am experienced when it comes to CakePhp. The problem occurs after logging in and creating a session, then quickly refresh the page multiple times. Sometimes the result will be an empty session.
The login uses the standard php $_SESSION array variables but the result is an empty session regardless if you use CakePhp’s built in session object. Out of the box CakePhp 1.2 is set up to run using the php.ini configurations and this is probably the problem. I’m assuming the way MediaTemple configured their (gs) servers prevent CakePhp from utilizing the session path in the php.ini. Why this only works half the time when you’re not quickly hitting refresh, I have yet to figure out.
Solution:
Luckily the solution is simple thanks the CakePhp’s built in session handling. Simply change the following line in the core.php configuration file:
Configure::write('Session.save', 'php');
to:
Configure::write('Session.save', 'cake');
This tells the CakePhp configuration to use it’s built in session handling. Make sure the “app/tmp” directory is writable and everything should work correctly. This fix worked for me but if anyone can verify the problem that would get rid of these lingering question marks in my head. If this fix works for you, I’m glad I could waste the hours trying to figure it out for you.























Thank you very much. I had the same problem and this finally fixed that.
Hi,
In my case the session is stored correctly but when it redirect to other controller the session is lost.
So did this fix your problem Ritesh?
Thank you!! problem fixed!
It works. I have to make /app/tmp to be 777
Is it safety ?
Anyhow thank you very much ^________^
That’s probably not completely safe but it sounds like your host set it up that way so you have no other choice