I have customers_contoller.php in frontend
function login() {
if(!empty($this->data)) {
# Call function from Customer to insert Registration Data
$loginData = ClassRegistry::init('Customer')->checkLogin($this->data['email'], $this->data['password']);
if(isset($loginData) && !empty($loginData)) {
$this->Session->write('Session.userid',$loginData['Customer']['id']);
$this->Session->write('Session.email',$loginData['Customer']['email']);
$this->redirect(HTTP_PATH."my-profile");
exit;
} else {
$this->Session->setFlash('Please enter valid Username/Password','default',array('class'=>'flash_bad'));
$this->redirect(HTTP_PATH."customer/login");
exit;
}
}
}
and in model customer.php,
function checkLogin($email,$password) {
$loginData = $this->find('first', array('conditions' => array('Customer.email' => $email, 'Customer.password' => sha1($password), 'Customer.is_active' => 'Yes')));
return $loginData;
}
most of time Login working fine, but sometime login not working and also doesn't get Error Message. Only refresh page every time on login.
I have just check all this things i found that when i can't login in my website at that time browser's cache show '/app/' for Session path but i have set actual Session path in before_filter() function in app_controller.php using $this->Session->path = '/';
I just remove all the browser's cache and try for login, now it is working fine.
Can anyone explain me what is the issue? it occurs randomly so i can't find root of the issue.
Possible reason of your problem is that Session is lost because of improper Cookie Path transmitted to browser. It may be happened randomly because of mixing of Session binding strategies of PHP (like by GET-parameter or by Cookies).
You have wrongly set up
$this->Session->path parameter
. It maps to session.cookie_path option of PHP. See quite similar example in this post.session.cookie_path
should exclude protocol, host and eventually port, so leave just root of you website'/'
:See also description of Domain and Path options of cookies.
EDIT: In order to further investigate reason of Session misconfiguration, debug
SessionComponent
andCakeSession
classes near$base
argument passed to constructor:I guess it was somehow passed wrongly, and you received
/app/
cookie path in the browser.For anyone else that may be interested, I had a similar problem on a new user's machine. It turned out that the machine was not syncing correctly with the internet time, and the machine had the date set to one day in the future. No errors were displayed, but the Auth session was destroyed on redirect, and I would always be redirected to the login page. Updating the time on the computer and restarting Chrome helped. (Strangely, this wasn't a problem in Firefox.)