I have an application written with PhalconPHP. I used phalcon command line tools to build up things. I want to implement a "remember-me" option for users. However, if I understand correctly, PhalconPHP creates cookies with unique session ids and an encryption (encryption part, I like). So, whenever users session is gone, I lost access to the cookie. How can I fix this?
I actually do not destroy the session, I just use cmd + Q to quit my browser after I set session and cookie. I tried with encryption and without.
To be more clear : I do not get any errors. Just can't find the cookie back. I got "no cookie found" echoed after I close the browser and turn it on again.
As a code example, below is how I try to achieve this feature;
My services.php
/**
* Start the session the first time some component request the session service
*/
$di->setShared('session', function () {
$session = new SessionAdapter();
//$session->setId('crowgadgets');
$session->start();
return $session;
});
/**
* Set crypt for cookie encryption
*/
$di->set('crypt', function () {
$crypt = new Crypt();
$crypt->setKey('-#1+%&/k5l6&olr$'); // Use your own key!
return $crypt;
});
/**
* Set cookie universal
*/
$di->setShared('cookies', function () {
$cookies = new Cookies();
//$cookies->useEncryption(true);
return $cookies;
});
Set the cookie in controller;
$this->cookies->set('remember-me', $auth['id'], time() + 15 * 86400);
Get the cookie in controller;
if ($this->cookies->has('remember-me')) {
$user_id = (string) $this->cookies->get('remember-me');
} else {
echo "no cookie found";
die();
}