[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*

   3  $Id: sessions.php 14 2006-07-28 17:42: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        return '';
  38      }
  39  
  40      function _sess_write($key, $val) {
  41        global $SESS_LIFE;
  42  
  43        $expiry = time() + $SESS_LIFE;
  44        $value = $val;
  45  
  46        $check_query = tep_db_query("select count(*) as total from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
  47        $check = tep_db_fetch_array($check_query);
  48  
  49        if ($check['total'] > 0) {
  50          return tep_db_query("update " . TABLE_SESSIONS . " set expiry = '" . tep_db_input($expiry) . "', value = '" . tep_db_input($value) . "' where sesskey = '" . tep_db_input($key) . "'");
  51        } else {
  52          return tep_db_query("insert into " . TABLE_SESSIONS . " values ('" . tep_db_input($key) . "', '" . tep_db_input($expiry) . "', '" . tep_db_input($value) . "')");
  53        }
  54      }
  55  
  56      function _sess_destroy($key) {
  57        return tep_db_query("delete from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($key) . "'");
  58      }
  59  
  60      function _sess_gc($maxlifetime) {
  61        tep_db_query("delete from " . TABLE_SESSIONS . " where expiry < '" . time() . "'");
  62  
  63        return true;
  64      }
  65  
  66      session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
  67    }
  68  
  69    function tep_session_start() {
  70      global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS;
  71  
  72      $sane_session_id = true;
  73  
  74      if (isset($HTTP_GET_VARS[tep_session_name()])) {
  75        if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_GET_VARS[tep_session_name()]) == false) {
  76          unset($HTTP_GET_VARS[tep_session_name()]);
  77  
  78          $sane_session_id = false;
  79        }
  80      } elseif (isset($HTTP_POST_VARS[tep_session_name()])) {
  81        if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_POST_VARS[tep_session_name()]) == false) {
  82          unset($HTTP_POST_VARS[tep_session_name()]);
  83  
  84          $sane_session_id = false;
  85        }
  86      } elseif (isset($HTTP_COOKIE_VARS[tep_session_name()])) {
  87        if (preg_match('/^[a-zA-Z0-9]+$/', $HTTP_COOKIE_VARS[tep_session_name()]) == false) {
  88          $session_data = session_get_cookie_params();
  89  
  90          setcookie(tep_session_name(), '', time()-42000, $session_data['path'], $session_data['domain']);
  91  
  92          $sane_session_id = false;
  93        }
  94      }
  95  
  96      if ($sane_session_id == false) {
  97        tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
  98      }
  99      return session_start();
 100    }
 101  
 102    function tep_session_register($variable) {
 103      global $session_started;
 104  
 105      if ($session_started == true) {
 106        if (PHP_VERSION < 4.3) {
 107          return session_register($variable);
 108        } else {
 109          if (isset($GLOBALS[$variable])) {
 110            $_SESSION[$variable] =& $GLOBALS[$variable];
 111          } else {
 112            $_SESSION[$variable] = null;
 113          }
 114        }
 115      }
 116  
 117      return false;
 118    }
 119  
 120    function tep_session_is_registered($variable) {
 121      if (PHP_VERSION < 4.3) {
 122        return session_is_registered($variable);
 123      } else {
 124        return isset($_SESSION) && array_key_exists($variable, $_SESSION);
 125      }
 126    }
 127  
 128    function tep_session_unregister($variable) {
 129      if (PHP_VERSION < 4.3) {
 130        return session_unregister($variable);
 131      } else {
 132        unset($_SESSION[$variable]);
 133      }
 134    }
 135  
 136    function tep_session_id($sessid = '') {
 137      if (!empty($sessid)) {
 138        return session_id($sessid);
 139      } else {
 140        return session_id();
 141      }
 142    }
 143  
 144    function tep_session_name($name = '') {
 145      if (!empty($name)) {
 146        return session_name($name);
 147      } else {
 148        return session_name();
 149      }
 150    }
 151  
 152    function tep_session_close() {
 153      if (PHP_VERSION >= '4.0.4') {
 154        return session_write_close();
 155      } elseif (function_exists('session_close')) {
 156        return session_close();
 157      }
 158    }
 159  
 160    function tep_session_destroy() {
 161      return session_destroy();
 162    }
 163  
 164    function tep_session_save_path($path = '') {
 165      if (!empty($path)) {
 166        return session_save_path($path);
 167      } else {
 168        return session_save_path();
 169      }
 170    }
 171  
 172    function tep_session_recreate() {
 173      if (PHP_VERSION >= 4.1) {
 174        $session_backup = $_SESSION;
 175  
 176        unset($_COOKIE[tep_session_name()]);
 177  
 178        tep_session_destroy();
 179  
 180        if (STORE_SESSIONS == 'mysql') {
 181          session_set_save_handler('_sess_open', '_sess_close', '_sess_read', '_sess_write', '_sess_destroy', '_sess_gc');
 182        }
 183  
 184        tep_session_start();
 185  
 186        $_SESSION = $session_backup;
 187        unset($session_backup);
 188      }
 189    }
 190  ?>


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