
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.15 KB | hits: 16 | expires: Never
CakePHP not saving my cookie
$cookie=$this->read('Auth.User');
if(empty($cookie) and !empty($this->data)){
if($this->Auth->login()) {
if(!empty($this->data['User']['remember_me'])){
$cookie = array('id' => $this->Auth->user('id'),
);
$expires=strtotime($this->appConfigurations['remember_me'],time());
$this->Cookie->write('Auth.User', $cookie, false, $this->appConfigurations['remember_me']);
}
}
}
$cookieValue=$this->Auth->user('id');
setcookie('CakeCookie[Auth][User]',$cookieValue,$expires,'/');
function login() {
$cookie = $this->Cookie->read('Auth.User');
debug($cookie); // Just a test
if ($this->Auth->user('id')) {
if(!empty($this->data)) {
$cookie = array(
'username' => $this->data['User']['username'],
'password' => $this->data['User']['password']
);
$this->Cookie->write('Auth.User', $cookie, false, '+2 weeks');
}
$this->redirect('/');
}
elseif (!empty($cookie)) {
if ($this->Auth->login($cookie)) {
$this->redirect('/');
}
}
}