In my prestashop a user (that is not a client or an admin) can create a "side" account (that is not a prestashop account) to do something special on the site.
I have created the everything to do that but when the user connect i can not keep the data during the session.
I've look for a way to keep the data and the only thing i see is the smarty cookie. Fine by me BUT i can not control the lifetime of that cookie. And i need this cookie to die when the user close the browser.
So i've tried to do a session, but i can't get it to work and i didn't see a way to do a cookie that doesn't last.
Anyone has an idea to do a session like data, or to handle the cookie lifespan?
Thank you
You can use the CookieCore
class
//to write
$cookie = new Cookie('my_cookie'); //make your own cookie
$cookie->setExpire(time() + 20 * 60); // 20 minutes for example
$cookie->variable_name = 'hello';
$cookie->write();
//to read
$cookie = new Cookie('my_cookie');
echo $cookie->variable_name;
//hello
I gonna add to the message of UnLoCo.
For people looking for a cookie that die at the end of the session, just put the
$cookie->setExpire(0);
NB the cookie will die only when the browser is completly close (i have an extention feedly that let the browser open, so i though there was a bug)
And last thing if you want to kill the cookie yourself
$cookie = new Cookie('my_cookie');
$cookie->variable_name = null;
$cookie->write();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With