Permalink
Browse files

Let PHP handle the session garbage collection to have the same behavi…

…our as file based sessions regarding session life time

Increase session ID field to char(128) to better support session.hash_function and session.hash_bits_per_character
  • Loading branch information...
1 parent 22b68ad commit 3f462774a510f73ae272e3d6a12576b991d546e2 @haraldpdl committed Feb 18, 2014
@@ -1,8 +1,8 @@
<?php
/**
* osCommerce Online Merchant
- *
- * @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
+ *
+ * @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
@@ -79,10 +79,6 @@ public function handlerClose() {
public function handlerRead($id) {
$data = array('id' => $id);
- if ( $this->_life_time > 0 ) {
- $data['expiry'] = time();
- }
-
$result = OSCOM::callDB('Session\Database\Get', $data, 'Core');
if ( $result !== false ) {
@@ -102,7 +98,7 @@ public function handlerRead($id) {
public function handlerWrite($id, $value) {
$data = array('id' => $id,
- 'expiry' => time() + $this->_life_time,
+ 'expiry' => time(),
'value' => base64_encode($value));
return OSCOM::callDB('Session\Database\Save', $data, 'Core');
@@ -127,9 +123,7 @@ public function handlerDestroy($id) {
*/
public function handlerClean($max_life_time) {
-// $max_life_time is already added to the time in the _custom_write method
-
- $data = array('expiry' => time());
+ $data = array('expiry' => $max_life_time);
return OSCOM::callDB('Session\Database\DeleteExpired', $data, 'Core');
}
@@ -1,8 +1,8 @@
<?php
/**
* osCommerce Online Merchant
- *
- * @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
+ *
+ * @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
@@ -19,7 +19,7 @@ public static function execute($data) {
$OSCOM_PDO = Registry::get('PDO');
$Qsession = $OSCOM_PDO->prepare('delete from :table_sessions where expiry < :expiry');
- $Qsession->bindInt(':expiry', $data['expiry']);
+ $Qsession->bindInt(':expiry', time() - $data['expiry']);
$Qsession->execute();
return ( $Qsession->rowCount() > 0 );
@@ -1,8 +1,8 @@
<?php
/**
* osCommerce Online Merchant
- *
- * @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
+ *
+ * @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
* @license BSD License; http://www.oscommerce.com/bsdlicense.txt
*/
@@ -18,19 +18,8 @@ class Get {
public static function execute($data) {
$OSCOM_PDO = Registry::get('PDO');
- $sql_query = 'select value from :table_sessions where id = :id';
-
- if ( isset($data['expiry']) ) {
- $sql_query .= ' and expiry >= :expiry';
- }
-
- $Qsession = $OSCOM_PDO->prepare($sql_query);
+ $Qsession = $OSCOM_PDO->prepare('select value from :table_sessions where id = :id');
$Qsession->bindValue(':id', $data['id']);
-
- if ( isset($data['expiry']) ) {
- $Qsession->bindInt(':expiry', $data['expiry']);
- }
-
$Qsession->execute();
return $Qsession->fetch();
@@ -71,7 +71,7 @@
*/
public function start() {
- if ( $this->_life_time > 0 ) {
+ if ( isset($this->_life_time) ) {
ini_set('session.gc_maxlifetime', $this->_life_time);
} else {
$this->_life_time = ini_get('session.gc_maxlifetime');
@@ -1,6 +1,6 @@
-- osCommerce Online Merchant
--
--- @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
+-- @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
-- @license BSD License; http://www.oscommerce.com/bsdlicense.txt
DROP TABLE IF EXISTS osc_address_book CASCADE;
@@ -694,7 +694,7 @@ CREATE INDEX osc_reviews_languages_id_idx ON osc_reviews USING btree (languages_
DROP TABLE IF EXISTS osc_sessions CASCADE;
CREATE TABLE osc_sessions (
- id char(32) NOT NULL,
+ id char(128) NOT NULL,
expiry integer NOT NULL,
value text NOT NULL,
PRIMARY KEY (id)
@@ -1,6 +1,6 @@
# osCommerce Online Merchant
#
-# @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
+# @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
# @license BSD License; http://www.oscommerce.com/bsdlicense.txt
SET FOREIGN_KEY_CHECKS = 0;
@@ -656,7 +656,7 @@ CREATE TABLE osc_reviews (
DROP TABLE IF EXISTS osc_sessions;
CREATE TABLE osc_sessions (
- id char(32) NOT NULL,
+ id char(128) NOT NULL,
expiry int unsigned NOT NULL,
value text NOT NULL,
PRIMARY KEY (id)

0 comments on commit 3f46277

Please sign in to comment.