[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/functions/ -> sessions.php (source)

   1  <?php
   2  /*

   3  $Id: sessions.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12    if ( (PHP_VERSION >= 4.3) && ((bool)ini_get('register_globals') == false) ) {
  13      @ini_set('session.bug_compat_42', 1);
  14      @ini_set('session.bug_compat_warn', 0);
  15    }
  16  
  17    if (STORE_SESSIONS == 'mysql') {
  18      if (!$SESS_LIFE = get_cfg_var('session.gc_maxlifetime')) {
  19        $SESS_LIFE = 1440;
  20      }
  21  
  22      function _sess_open($save_path, $session_name) {
  23        return true;
  24      }
  25  
  26      function _sess_close() {
  27        return true;
  28      }
  29  
  30      function _sess_read($key) {
  31        $value_query = tep_db_query("select value from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "' and expiry > '" . time() . "'");
  32        $value = tep_db_fetch_array($value_query);
  33  
  34        if (isset($value['value'])) {
  35          return $value['value'];
  36        }
  37  
  38        return '';
  39      }
  40  
  41      function _sess_write($key, $val) {
  42        global $SESS_LIFE;
  43  
  44        $expiry = time() + $SESS_LIFE;
  45        $value = $val;
  46  
  47        $check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
  48        $check = tep_db_fetch_array($check_query);
  49  
  50        if ($check['total'] > 0) {
  51          return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
  52        } else {
  53          return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
  54        }
  55      }
  56  
  57      function _sess_destroy($key) {
  58        return tep_db_query("delete from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
  59      }
  60  
  61      function _sess_gc($maxlifetime) {
  62        tep_db_query("delete from " . TABLE_SESSIONS . " where expiry < '" . time() . "'");
  63  
  64        return true;
  65      }
  66  
  67      session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
  68    }
  69  
  70    function tep_session_start() {
  71      global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS;
  72  
  73      $sane_session_id = true;
  74  
  75      if (isset($HTTP_GET_VARS[tep_session_name()])) {
  76        if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_GET_VARS[tep_session_name()]) == false) {
  77          unset($HTTP_GET_VARS[tep_session_name()]);
  78  
  79          $sane_session_id = false;
  80        }
  81      } elseif (isset($HTTP_POST_VARS[tep_session_name()])) {
  82        if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_POST_VARS[tep_session_name()]) == false) {
  83          unset($HTTP_POST_VARS[tep_session_name()]);
  84  
  85          $sane_session_id = false;
  86        }
  87      } elseif (isset($HTTP_COOKIE_VARS[tep_session_name()])) {
  88        if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_COOKIE_VARS[tep_session_name()]) == false) {
  89          $session_data = session_get_cookie_params();
  90  
  91          setcookie(tep_session_name(), '', time()-42000, $session_data['path'], $session_data['domain']);
  92  
  93          $sane_session_id = false;
  94        }
  95      }
  96  
  97      if ($sane_session_id == false) {
  98        tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
  99      }
 100      return session_start();
 101    }
 102  
 103    function tep_session_register($variable) {
 104      if (PHP_VERSION < 4.3) {
 105        return session_register($variable);
 106      } else {
 107        if (isset($GLOBALS[$variable])) {
 108          $_SESSION[$variable] =& $GLOBALS[$variable];
 109        } else {
 110          $_SESSION[$variable] = null;
 111        }
 112      }
 113  
 114      return false;
 115    }
 116  
 117    function tep_session_is_registered($variable) {
 118      if (PHP_VERSION < 4.3) {
 119        return session_is_registered($variable);
 120      } else {
 121        return isset($_SESSION) && array_key_exists($variable, $_SESSION);
 122      }
 123    }
 124  
 125    function tep_session_unregister($variable) {
 126      if (PHP_VERSION < 4.3) {
 127        return session_unregister($variable);
 128      } else {
 129        unset($_SESSION[$variable]);
 130      }
 131    }
 132  
 133    function tep_session_id($sessid = '') {
 134      if ($sessid != '') {
 135        return session_id($sessid);
 136      } else {
 137        return session_id();
 138      }
 139    }
 140  
 141    function tep_session_name($name = '') {
 142      if ($name != '') {
 143        return session_name($name);
 144      } else {
 145        return session_name();
 146      }
 147    }
 148  
 149    function tep_session_close() {
 150      if (PHP_VERSION >= '4.0.4') {
 151        return session_write_close();
 152      } elseif (function_exists('session_close')) {
 153        return session_close();
 154      }
 155    }
 156  
 157    function tep_session_destroy() {
 158      return session_destroy();
 159    }
 160  
 161    function tep_session_save_path($path = '') {
 162      if ($path != '') {
 163        return session_save_path($path);
 164      } else {
 165        return session_save_path();
 166      }
 167    }
 168  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7