Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop 1.6 session/cookie with smarty

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

like image 582
David Aclub Avatar asked Nov 10 '14 09:11

David Aclub


2 Answers

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
like image 143
unloco Avatar answered Nov 10 '22 04:11

unloco


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();
like image 3
David Aclub Avatar answered Nov 10 '22 05:11

David Aclub