I have an issue with cakephp’s login functionality. When I try to login under chrome, my username/password are accepted, but the session is not being stored correctly. I’ve done some debugging/searching and found that the root of the problem (at least I think) is that the session id is not being stored in chrome’s cookies. When I use firefox the login works as expected and looking at the cookies shows the session id in a cookie under the name ‘CAKEPHP’. However, when I look at chrome’s cookies after logging in/accessing a page, there is no cookie containing the session id. As a result, the session id seems to be changing every time I load a page. I’ve been googling and searching for a solution for this for hours with no luck. I did find something similar at http://www.pixelastic.com/blog/273:losing-session-request-cakephp-chrome, but using this solution did not work for me. I don’t know if it was intended for an older version of cakephp or not. I’m using version 2.0.
I’ll post the login code I’m using, but I took it directly from a tutorial so I don’t really think it is the problem (especially since it works in FF):
public function login() {
Security::setHash('sha1');
if ($this->Auth->login()) {
$this->Session->setFlash(__('Welcome'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
It turned out to be an issue with my setup. In case anyone is having a problem like this: I was running the server in a virtual machine, and the problem seems to be related to the host computer going to sleep/low power mode while the VM is running. When the host computer wakes up, the issue with chrome cookies starts happening. Rebooting the VM fixed the problem.