User Tools

Site Tools


tutorials:zencartmods:sessions.html

This is an old revision of the document!


Changing Session Length

By default, a zencart session will timeout after 24 minutes of inactivity. This will log someone out, or delete their temporary shopping cart if they weren't logged in. Depending on your shop you might want this to be longer or shorter.

Before we begin, make sure that the STORE_SESSIONS constant in includes/configure.php is set to 'db' and not ''.

You should have this line:

define('STORE_SESSIONS', 'db');

If this is not set to 'db', then this mod will certainly not work.

Ok, so to change the session length, find these lines in includes/functions/sessions.php

  if (STORE_SESSIONS == 'db') {
    if (defined('DIR_WS_ADMIN')) {
      if (!$SESS_LIFE = (SESSION_TIMEOUT_ADMIN + 900)) {
        $SESS_LIFE = (SESSION_TIMEOUT_ADMIN + 900);
      }
    } else {
      if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) {
        $SESS_LIFE = 1440;
      }
    }

As you can probably tell, there are 2 ways we can go about this.

The first is to edit php.ini on your server and set session.gc_maxlifetime to a new value.

The other option, which you might prefer if you don't have access to your php.ini file, is to replace the above lines of code with

  if (STORE_SESSIONS == 'db') {
    if (defined('DIR_WS_ADMIN')) {
      if (!$SESS_LIFE = (SESSION_TIMEOUT_ADMIN + 900)) {
        $SESS_LIFE = (SESSION_TIMEOUT_ADMIN + 900);
      }
    } else {                                                                                                                                                                                                        
        $SESS_LIFE = 86400;                                                                                                                                                                                                                                                            
    }

The $SESS_LIFE variable is stored in seconds, so 86400 = (24 * 60 * 60) = 1 day.

For extra credit, you can even set the value to a db-stored variable for easy updating.

Note: It is very important not to do this mod if you are using filesystem-based sessions. While zencart manages db sessions, filesystem based sessions will get garbage-collected by the server regardless of zencarts $SESS_LIFE variable.

/home/ladyada/public_html/wiki/data/attic/tutorials/zencartmods/sessions.html.1315943429.txt.gz · Last modified: 2016/01/28 18:05 (external edit)