Probleme wit cookie in Cakephp 2.2.5


#1

Hello ,

I develop a site with CakePhp 2.2.5 and I would like to put a system of “remember me” when connecting, so I go through the cookies but I have a problem reading the cookie in the App Controller :

This is my code :

In UsersController.php :

if ($remember == "true") {

  $this->log("remember == true");
  $token = bin2hex(openssl_random_pseudo_bytes(250));
  $this->User->id = $user['User']['id'];
  $this->User->savefield('remember' , $token);
  $this->log("on ecrit le cookie");

  $this->Cookie->write('remember' , 'ddd' , time() + 3600);
  $this->log("le cookie a ete ecrit");
  $this->log("COOKIE REMEMBER (UserController) : " . $this->Cookie->read('remember'));

}

In AppController.php :
class AppController extends Controller {

 public $components = array(
    'Session' ,
    'Cookie' ,
    'Auth' => array(
        'loginAction' => array('controller' => 'pages', 'action' => 'index'),
        'authenticate' => array(
            'Form' => array(
                'scope' => array('User.active' => 1)
            )
        )
    ),
);

public $uses = array(‘User’);

public function beforeFilter() {

 parent::beforeFilter();

 $this->Cookie->key = '39lbkutg1i2l0kta6785d8qki5';
 $this->Cookie->httpOnly = true;

 $this->log("COOKIE REMEMBER (APPController) : " . $this->Cookie->read('remember'));
}

}

The cookie is not recovered in the App Controller as the logs show when I log in and I check the box “Remember me”.

Thank you for your help.