0
votes

Recently I moved my cakephp site from a hosting service to an other. The page was working like a charm, but now I'm having the issue, that my sessions randomly drop. I'm on a shared hosting service, so I changed cake's session defaults from php to cake, now my sessions are saved to my tmp/sessions folder. (but it wasn't working with php either)

Followed my session's way with Firebug:

  1. When i log into the page, i have a Sessionid, and in the tmp/sessions folder i have the corresponding sess_{sessionid} file too.
  2. After a few clicks on some pages (totally random) my sessionid changes and i'm "logged out". The session file with which i've logged in, remained in the directory.

My session settings in core.php right now:

Configure::write('Session', array(
    'defaults' => 'cake'
));

I'm using the 2.3.8 version of Cake.


Update:

Finally i found the problem thanks to Nick. I checked the Cakephp error files, and found out that i only got logged out, when i visited a page containing an element, which was not on the server ( eg a picture was missing). So i went to Firebug, and check what the Net tab says. On the new Host service i got a 404 Not Found response AND a new session id set in the response, whilst on the other servers i tested the page, i simply got a 404 Not Found. If i randomly generate links to not existing files like (domain/test.jpg) i get the same results.

2
This looks like a classic issue with php cookie expiring before the session. Check stackoverflow.com/questions/11304390/… - user221931
unfortunately not, the expiration of the session cookie is set to a few hours (and that is correcty set, checked in firebug), but i'm logged out within a minute. - baliika

2 Answers

0
votes

Try these settings, in Firefox you can install the web develop extension, then you can view your cookie to see if it is all set correct.

Configure::write('Session', array(
'defaults' => 'php',
'cookie' => 'yourdomain',
'timeout' => 44640,
));
0
votes

Check any components that you are using for whitespace (usually at the end of the file).

I came across this recently whilst helping a client with their existing CakePHP site, when logged in one particular page that called a component was killing $this->Session->read(‘Auth’).

There is a CakePHP shell that you can use to find whitespace.