I checked this Cakephp cookie always get deleted automatically but, no go. That is not exactly what I’ve been looking for.
The cookie which Auto Login uses is getting deleted.
Here is what did:
public function login( ) {
if ($this->Auth->user('id')) {
$this->redirect(array('action' => 'dashboard'));
}
if ($this->request->is('post')) {
if($this->request->data['User']['auto_login']):
$this->AutoLogin->write($this->request->data['User']['email'],
$this->request->data['User']['password']);
endif;
if ($this->Auth->login( )) {
//$this->redirect(array('controller' => 'users', 'action' => 'edit'));
return $this->redirect($this->Auth->redirect( ));
}
else
{
$this->Session->setFlash(__('Username and Password is incorrect'), 'default', array( ), 'auth');
}
}
else {
if($this->AutoLogin->read()):
$AllData = $this->AutoLogin->read();
$AllData['username'] = 'email';
$AllData['password'] = 'password';
$check = $this->User->find('first', array('username' => 'email', 'password' => 'password'));
if($check):
$this->Auth->user($check);
$this->Auth->redirect();
endif;
$this->redirect(array('action' => 'login'));
endif;
}
It sets cookie, it does every damn thing!
But, on browser exit, it just disappears! Yes, tried with variety of browsers and also checked if browser settings is doing it.
My AppController is loading:
public $components = array('AutoLogin','Auth' => array('autoRedirect' => false), 'Cookie', 'RequestHandler', 'Session', 'Facebook.Connect' => array('model' => 'User') );//, //'DebugKit.Toolbar');
Now, here is the catch, when I check for Resources under Inspect Element, it shows me 2 things: PHPSESSID and CakeCookie[autoLogin] , PHPSESSID – type is session and expires – blank. CakeCookie type is cookie and expires after a month!
Since it ‘looks’ like native PHP, I thought of checking for session_start() function and I found it! It was Facebook component but, disabling it, did prevent PHPSESSID from coming but , still cookie would get deleted on browser exit.
Please advice.
Thanks in advance.
Open Facebook.php file in Facebook plugin files.
On line 4 or 5, under __construct, comment out the line which says session_start();
Ideally, CakePHP loads all the plugins which results in PHPSESSID getting set. Comment this out and even Facebook will effectively work.
Also, make sure that you create a folder called ‘sessions’ under your tmp folder and mark it chmod -R 0777 sessions/ , refresh your application.