I followed the answer from here, but it didn’t work for me:
Is it possible to continue the session even after closing the browser?
Here is the code I tried:
$session_life = 2592000;
session_set_cookie_params($session_life);
session_name('my_cart');
session_start();
setcookie(session_name(),session_id(),time()+$session_life);
The problem is that every time the browser closes, I still get a new session_id, not the old one.
I use a database to store items in 'my_cart', and session_id is just used to identify the user to show them their own cart.
What is the best way to keep users for 30 days?
This is the code I ended up in:
$cart_name = "my_cart";
$cart_life = 2592000;
session_start();
if (isset($_COOKIE[$cart_name])) {
session_id($_COOKIE[$cart_name]);
}
setcookie($cart_name, session_id(), time()+$cart_life);
source
share