Cart session duration

s3am
Posts: 3
Joined: 2014-05-17 21:02

Cart session duration

Post by s3am » 2017-01-23 18:00

Hello Fred

Do you thing it's possible to set a cart session duration, 1 week for example.

Best regards

Adel

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Cart session duration

Post by Fred » 2017-01-30 13:56

To be honest I haven' t looked at how long the cart session would last normally. I would assume the "standard" 24 minutes as set by your host.

if you have mod_php5.c installed on your server you could try the following in your htaccess file
3600 is the number of seconds, in this case 60 minutes.

Code: Select all

<IfModule mod_php5.c>
    #Session timeout
    php_value session.cookie_lifetime 3600
    php_value session.gc_maxlifetime 3600
</IfModule>
If you not sure about the availability if mod_php5.c on your server you can still add the above to the htaccess file. It just would not work. So nothing to loose.

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Cart session duration

Post by Fred » 2017-01-30 14:00

You can also try this. Add it to a file that get loaded on every page on your site.
Obviously adjust the seconds to suit.

Code: Select all

// Set max_life
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
    // last request was more than 30 minutes ago
    session_unset();     // unset $_SESSION variable for the run-time 
    session_destroy();   // destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp

// Prevent session fixation
if (!isset($_SESSION['CREATED'])) {
    $_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > 1800) {
    // session started more than 30 minutes ago
    session_regenerate_id(true);    // change session ID for the current session and invalidate old session ID
    $_SESSION['CREATED'] = time();  // update creation time
}
// End Set max_life

Post Reply