Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.15 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. CakePHP not saving my cookie
  2. $cookie=$this->read('Auth.User');
  3. if(empty($cookie) and !empty($this->data)){
  4.     if($this->Auth->login()) {
  5.         if(!empty($this->data['User']['remember_me'])){
  6.             $cookie = array('id' => $this->Auth->user('id'),
  7.             );
  8.             $expires=strtotime($this->appConfigurations['remember_me'],time());
  9.             $this->Cookie->write('Auth.User', $cookie, false, $this->appConfigurations['remember_me']);
  10.         }
  11.     }
  12. }
  13.        
  14. $cookieValue=$this->Auth->user('id');
  15. setcookie('CakeCookie[Auth][User]',$cookieValue,$expires,'/');
  16.        
  17. function login() {
  18.     $cookie = $this->Cookie->read('Auth.User');
  19.     debug($cookie); // Just a test
  20.     if ($this->Auth->user('id')) {
  21.         if(!empty($this->data)) {
  22.             $cookie = array(
  23.                 'username' => $this->data['User']['username'],
  24.                 'password' => $this->data['User']['password']
  25.             );
  26.             $this->Cookie->write('Auth.User', $cookie, false, '+2 weeks');
  27.         }
  28.         $this->redirect('/');
  29.     }
  30.     elseif (!empty($cookie)) {
  31.         if ($this->Auth->login($cookie)) {
  32.             $this->redirect('/');
  33.         }
  34.     }
  35. }