Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

153
 
199
 
199
 
session.php
_> 11 <?php
  22 /*
<> 3 -  $Id: session.php 153 2005-08-04 12:57:59Z hpdl $
   3+  $Id: session.php 199 2005-09-22 15:56:13Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
  77 
<> 8 -  Copyright (c) 2004 osCommerce
   8+  Copyright (c) 2005 osCommerce
99 
  1010   Released under the GNU General Public License
  1111 */
  1212 
  1313   class osC_Session {
<> 14 -    var $is_started,
  15 -        $save_path,
  16 -        $name,
  17 -        $id;
1814 
  1915 /* Private variables */
<> 20 -    var $_cookie_parameters;
   16+    var $_cookie_parameters,
   17+        $_is_started = false,
   18+        $_id,
   19+        $_name,
   20+        $_save_path;
2121 
  2222 // class constructor
<> 23 -    function osC_Session() {
  24 -      $this->setName('osCsid');
   23+    function osC_Session($name = 'sid') {
   24+      $this->setName($name);
2525       $this->setSavePath(DIR_FS_WORK);
  2626       $this->setCookieParameters();
  2727 
     
 !
3333                                  array(&$this, '_destroy'),
  3434                                  array(&$this, '_gc'));
  3535       }
<> 36 -
  37 -      $this->setStarted(false);
3836     }
  3937 
  4038 // class methods
  4139     function start() {
  4240       $sane_session_id = true;
  4341 
<> 44 -      if (isset($_GET[$this->name])) {
  45 -        if (preg_match('/^[a-zA-Z0-9]+$/', $_GET[$this->name]) == false) {
  46 -          unset($_GET[$this->name]);
   42+      if (isset($_GET[$this->_name]) && (osc_empty($_GET[$this->_name]) || (ctype_alnum($_GET[$this->_name]) === false))) {
   43+        $sane_session_id = false;
   44+      } elseif (isset($_POST[$this->_name]) && (osc_empty($_POST[$this->_name]) || (ctype_alnum($_POST[$this->_name]) === false))) {
   45+        $sane_session_id = false;
   46+      } elseif (isset($_COOKIE[$this->_name]) && (osc_empty($_COOKIE[$this->_name]) || (ctype_alnum($_COOKIE[$this->_name]) === false))) {
   47+        $sane_session_id = false;
   48+      }
4749 
<> 48 -          $sane_session_id = false;
   50+      if ($sane_session_id === false) {
   51+        if (isset($_COOKIE[$this->_name])) {
   52+          setcookie($this->getName(), '', time()-42000, $this->getCookieParameters('path'), $this->getCookieParameters('domain'));
4953         }
<> 50 -      } elseif (isset($_POST[$this->name])) {
  51 -        if (preg_match('/^[a-zA-Z0-9]+$/', $_POST[$this->name]) == false) {
  52 -          unset($_POST[$this->name]);
5354 
<> 54 -          $sane_session_id = false;
  55 -        }
  56 -      } elseif (isset($_COOKIE[$this->name])) {
  57 -        if (preg_match('/^[a-zA-Z0-9]+$/', $_COOKIE[$this->name]) == false) {
  58 -          unset($_COOKIE[$this->name]);
  59 -
  60 -          $sane_session_id = false;
  61 -        }
  62 -      }
  63 -
  64 -      if ($sane_session_id == false) {
6555         tep_redirect(tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false));
  6656       } elseif (session_start()) {
  6757         $this->setStarted(true);
<> 68 -
6958         $this->setID();
  7059 
  7160         return true;
     
 !
7463       return false;
  7564     }
  7665 
<> 77 -    function exists($variable) {
  78 -      if (isset($_SESSION[$variable])) {
  79 -        return true;
  80 -      }
  81 -
  82 -      return false;
   66+    function hasStarted() {
   67+      return $this->_is_started;
8368     }
  8469 
<> 85 -    function set($variable, &$value) {
  86 -      if ($this->is_started == true) {
  87 -        $_SESSION[$variable] = $value;
  88 -
  89 -        return true;
  90 -      }
  91 -
  92 -      return false;
  93 -    }
  94 -
  95 -    function remove($variable) {
  96 -      if ($this->exists($variable)) {
  97 -        unset($_SESSION[$variable]);
  98 -
  99 -        return true;
  100 -      }
  101 -
  102 -      return false;
  103 -    }
  104 -
  105 -    function &value($variable) {
  106 -      if (isset($_SESSION[$variable])) {
  107 -        return $_SESSION[$variable];
  108 -      }
  109 -
  110 -      return false;
  111 -    }
  112 -
11370     function close() {
<> 114 -      if (function_exists('session_write_close')) {
  115 -        return session_write_close();
  116 -      }
  117 -
  118 -      return true;
   71+      return session_write_close();
11972     }
  12073 
  12174     function destroy() {
<> 122 -      if (isset($_COOKIE[$this->name])) {
  123 -        unset($_COOKIE[$this->name]);
   75+      if (isset($_COOKIE[$this->_name])) {
   76+        unset($_COOKIE[$this->_name]);
12477       }
  12578 
  12679       if (STORE_SESSIONS == '') {
<> 127 -        if (file_exists($this->save_path . $this->id)) {
  128 -          @unlink($this->save_path . $this->id);
   80+        if (file_exists($this->_save_path . $this->_id)) {
   81+          @unlink($this->_save_path . $this->_id);
12982         }
  13083       }
  13184 
     
 !
147100     }
  148101 
  149102     function getSavePath() {
<> 150 -      return $this->save_path;
   103+      return $this->_save_path;
151104     }
  152105 
<>  106+    function getID() {
   107+      return $this->_id;
   108+    }
   109+
   110+    function getName() {
   111+      return $this->_name;
   112+    }
   113+
153114     function setName($name) {
  154115       session_name($name);
  155116 
<> 156 -      $this->name = session_name();
  157 -
  158 -      return true;
   117+      $this->_name = session_name();
159118     }
  160119 
  161120     function setID() {
<> 162 -      $this->id = session_id();
  163 -
  164 -      return true;
   121+      $this->_id = session_id();
165122     }
  166123 
  167124     function setSavePath($path) {
     
 !
171128 
  172129       session_save_path($path);
  173130 
<> 174 -      $this->save_path = session_save_path();
  175 -
  176 -      return true;
   131+      $this->_save_path = session_save_path();
177132     }
  178133 
  179134     function setStarted($state) {
<> 180 -      if ($state == true) {
  181 -        $this->is_started = true;
   135+      if ($state === true) {
   136+        $this->_is_started = true;
182137       } else {
<> 183 -        $this->is_started = false;
   138+        $this->_is_started = false;
<_ 184139       }
  185140     }
  186141