Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:20:31+00:00 2026-06-04T07:20:31+00:00

I followed the answer from here but it didn’t work for me: Is possible

  • 0

I followed the answer from here but it didn’t work for me:
Is possible to keep session even after the browser is closed?

Here is the code I tried:

$session_life = 2592000; // 30 days
session_set_cookie_params($session_life);
session_name('my_cart');
session_start();
// update the session_life
setcookie(session_name(),session_id(),time()+$session_life);

The problem with this is that every time the browser is closed I still get a new session_id, not the old one.

I am using a database to store the items in ‘my_cart’ and the session_id is just used to identify the user to show them their own cart.

What is the best way for me to keep the users cart alive for 30 days?


This is the code I ended up with:

$cart_name = "my_cart";
$cart_life = 2592000; // 30 days
session_start();
if (isset($_COOKIE[$cart_name])) {
    session_id($_COOKIE[$cart_name]);
}
setcookie($cart_name, session_id(), time()+$cart_life);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:20:32+00:00Added an answer on June 4, 2026 at 7:20 am

    I’ve had to do a similar thing with a site I wrote (allow a 30 minute period for a customer to enter a code)

    Rather than use a cookie (as you can’t guarantee that the customer would be returning to the site in the same browser), I stored the expiry time for the code against the user’s record. That way, whatever browser they accessed the page from (e.g., starting from mobile, finishing on a desktop), they would always expire at the same time.

    When the customer returns to the site, I compare the current time to the expiry time and act accordingly

    As you’re already storing the customer’s basket, I would add an expiry time against the record and then run a compare when the customer returns. It’s quite easy to do:

    update basket set expiryDateTime=date_add(now(),interval 7 day) where basketID=[xyz]
    

    If you want, you could even set the time of day to be a standard value (20:00) by using a bit more trickery in MySQL

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So followed all the basic tutorials. Am using Zend 1.8 but i keep getting
I followed the sitemap activation steps on the django site but i keep getting
I've followed the installation procedure from here and when I reach the Inspect Role
I followed the accepted answer here to alter the order of items in a
I've followed Adam's answer here and the Entity Framework now works and the Seed()
I've followed this answer to mock HttpContext, Request, Response and User and set Controller.ControllerContext
Followed this question about delayed_job and monit Its working on my development machine. But
I followed the explanation on the sIFR wiki, but can't seem to get accented
This might be a noob question, but can't find an answer anywhere. I have
Sorry if this is a question with a obvious answer but my knowledge with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.