Update to CodeIgniter 3.19
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.0.0
|
||||
@@ -57,6 +57,7 @@ class CI_Session {
|
||||
|
||||
protected $_driver = 'files';
|
||||
protected $_config;
|
||||
protected $_sid_regexp;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -91,6 +92,7 @@ class CI_Session {
|
||||
// Note: BC workaround
|
||||
elseif (config_item('sess_use_database'))
|
||||
{
|
||||
log_message('debug', 'Session: "sess_driver" is empty; using BC fallback to "sess_use_database".');
|
||||
$this->_driver = 'database';
|
||||
}
|
||||
|
||||
@@ -98,6 +100,7 @@ class CI_Session {
|
||||
|
||||
// Configuration ...
|
||||
$this->_configure($params);
|
||||
$this->_config['_sid_regexp'] = $this->_sid_regexp;
|
||||
|
||||
$class = new $class($this->_config);
|
||||
if ($class instanceof SessionHandlerInterface)
|
||||
@@ -130,7 +133,7 @@ class CI_Session {
|
||||
if (isset($_COOKIE[$this->_config['cookie_name']])
|
||||
&& (
|
||||
! is_string($_COOKIE[$this->_config['cookie_name']])
|
||||
OR ! preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookie_name']])
|
||||
OR ! preg_match('#\A'.$this->_sid_regexp.'\z#', $_COOKIE[$this->_config['cookie_name']])
|
||||
)
|
||||
)
|
||||
{
|
||||
@@ -238,10 +241,8 @@ class CI_Session {
|
||||
{
|
||||
return $prefix.$class;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
|
||||
}
|
||||
|
||||
log_message('debug', 'Session: '.$prefix.$class.".php found but it doesn't declare class ".$prefix.$class.'.');
|
||||
}
|
||||
|
||||
return 'CI_'.$class;
|
||||
@@ -314,8 +315,82 @@ class CI_Session {
|
||||
ini_set('session.use_strict_mode', 1);
|
||||
ini_set('session.use_cookies', 1);
|
||||
ini_set('session.use_only_cookies', 1);
|
||||
ini_set('session.hash_function', 1);
|
||||
ini_set('session.hash_bits_per_character', 4);
|
||||
|
||||
$this->_configure_sid_length();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Configure session ID length
|
||||
*
|
||||
* To make life easier, we used to force SHA-1 and 4 bits per
|
||||
* character on everyone. And of course, someone was unhappy.
|
||||
*
|
||||
* Then PHP 7.1 broke backwards-compatibility because ext/session
|
||||
* is such a mess that nobody wants to touch it with a pole stick,
|
||||
* and the one guy who does, nobody has the energy to argue with.
|
||||
*
|
||||
* So we were forced to make changes, and OF COURSE something was
|
||||
* going to break and now we have this pile of shit. -- Narf
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _configure_sid_length()
|
||||
{
|
||||
if (PHP_VERSION_ID < 70100)
|
||||
{
|
||||
$hash_function = ini_get('session.hash_function');
|
||||
if (ctype_digit($hash_function))
|
||||
{
|
||||
if ($hash_function !== '1')
|
||||
{
|
||||
ini_set('session.hash_function', 1);
|
||||
}
|
||||
|
||||
$bits = 160;
|
||||
}
|
||||
elseif ( ! in_array($hash_function, hash_algos(), TRUE))
|
||||
{
|
||||
ini_set('session.hash_function', 1);
|
||||
$bits = 160;
|
||||
}
|
||||
elseif (($bits = strlen(hash($hash_function, 'dummy', false)) * 4) < 160)
|
||||
{
|
||||
ini_set('session.hash_function', 1);
|
||||
$bits = 160;
|
||||
}
|
||||
|
||||
$bits_per_character = (int) ini_get('session.hash_bits_per_character');
|
||||
$sid_length = (int) ceil($bits / $bits_per_character);
|
||||
}
|
||||
else
|
||||
{
|
||||
$bits_per_character = (int) ini_get('session.sid_bits_per_character');
|
||||
$sid_length = (int) ini_get('session.sid_length');
|
||||
if (($bits = $sid_length * $bits_per_character) < 160)
|
||||
{
|
||||
// Add as many more characters as necessary to reach at least 160 bits
|
||||
$sid_length += (int) ceil((160 % $bits) / $bits_per_character);
|
||||
ini_set('session.sid_length', $sid_length);
|
||||
}
|
||||
}
|
||||
|
||||
// Yes, 4,5,6 are the only known possible values as of 2016-10-27
|
||||
switch ($bits_per_character)
|
||||
{
|
||||
case 4:
|
||||
$this->_sid_regexp = '[0-9a-f]';
|
||||
break;
|
||||
case 5:
|
||||
$this->_sid_regexp = '[0-9a-v]';
|
||||
break;
|
||||
case 6:
|
||||
$this->_sid_regexp = '[0-9a-zA-Z,-]';
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_sid_regexp .= '{'.$sid_length.'}';
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -529,7 +604,7 @@ class CI_Session {
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unmark flash
|
||||
* Unmark temp
|
||||
*
|
||||
* @param mixed $key Session data key(s)
|
||||
* @return void
|
||||
@@ -729,7 +804,7 @@ class CI_Session {
|
||||
*
|
||||
* Legacy CI_Session compatibility method
|
||||
*
|
||||
* @param mixed $data Session data key(s)
|
||||
* @param mixed $key Session data key(s)
|
||||
* @return void
|
||||
*/
|
||||
public function unset_userdata($key)
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
@@ -112,6 +112,23 @@ abstract class CI_Session_driver implements SessionHandlerInterface {
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* PHP 5.x validate ID
|
||||
*
|
||||
* Enforces session.use_strict_mode on PHP 5.x (7+ does it by itself)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function php5_validate_id()
|
||||
{
|
||||
if (PHP_VERSION_ID < 70000 && isset($_COOKIE[$this->_config['cookie_name']]) && ! $this->validateId($_COOKIE[$this->_config['cookie_name']]))
|
||||
{
|
||||
unset($_COOKIE[$this->_config['cookie_name']]);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cookie destroy
|
||||
*
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
@@ -109,7 +109,10 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan
|
||||
}
|
||||
|
||||
// Note: BC work-around for the old 'sess_table_name' setting, should be removed in the future.
|
||||
isset($this->_config['save_path']) OR $this->_config['save_path'] = config_item('sess_table_name');
|
||||
if ( ! isset($this->_config['save_path']) && ($this->_config['save_path'] = config_item('sess_table_name')))
|
||||
{
|
||||
log_message('debug', 'Session: "sess_save_path" is empty; using BC fallback to "sess_table_name".');
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -130,6 +133,8 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan
|
||||
return $this->_fail();
|
||||
}
|
||||
|
||||
$this->php5_validate_id();
|
||||
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
@@ -206,7 +211,7 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan
|
||||
$this->_db->reset_query();
|
||||
|
||||
// Was the ID regenerated?
|
||||
if ($session_id !== $this->_session_id)
|
||||
if (isset($this->_session_id) && $session_id !== $this->_session_id)
|
||||
{
|
||||
if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id))
|
||||
{
|
||||
@@ -337,6 +342,30 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan
|
||||
: $this->_fail();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate ID
|
||||
*
|
||||
* Checks whether a session ID record exists server-side,
|
||||
* to enforce session.use_strict_mode.
|
||||
*
|
||||
* @param string $id
|
||||
* @return bool
|
||||
*/
|
||||
public function validateId($id)
|
||||
{
|
||||
// Prevent previous QB calls from messing with our queries
|
||||
$this->_db->reset_query();
|
||||
|
||||
$this->_db->select('1')->from($this->_config['save_path'])->where('id', $id);
|
||||
empty($this->_config['match_ip']) OR $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']);
|
||||
$result = $this->_db->get();
|
||||
empty($result) OR $result = $result->row();
|
||||
|
||||
return ! empty($result);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -351,7 +380,7 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan
|
||||
{
|
||||
if ($this->_platform === 'mysql')
|
||||
{
|
||||
$arg = $session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : '');
|
||||
$arg = md5($session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : ''));
|
||||
if ($this->_db->query("SELECT GET_LOCK('".$arg."', 300) AS ci_session_lock")->row()->ci_session_lock)
|
||||
{
|
||||
$this->_lock = $arg;
|
||||
@@ -414,4 +443,4 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan
|
||||
|
||||
return parent::_release_lock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
@@ -76,6 +76,20 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
*/
|
||||
protected $_file_new;
|
||||
|
||||
/**
|
||||
* Validate SID regular expression
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_sid_regexp;
|
||||
|
||||
/**
|
||||
* mbstring.func_overload flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $func_overload;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -95,8 +109,13 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
}
|
||||
else
|
||||
{
|
||||
log_message('debug', 'Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.');
|
||||
$this->_config['save_path'] = rtrim(ini_get('session.save_path'), '/\\');
|
||||
}
|
||||
|
||||
$this->_sid_regexp = $this->_config['_sid_regexp'];
|
||||
|
||||
isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -129,6 +148,8 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
.$name // we'll use the session cookie name as a prefix to avoid collisions
|
||||
.($this->_config['match_ip'] ? md5($_SERVER['REMOTE_ADDR']) : '');
|
||||
|
||||
$this->php5_validate_id();
|
||||
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
@@ -148,18 +169,9 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
// which re-reads session data
|
||||
if ($this->_file_handle === NULL)
|
||||
{
|
||||
// Just using fopen() with 'c+b' mode would be perfect, but it is only
|
||||
// available since PHP 5.2.6 and we have to set permissions for new files,
|
||||
// so we'd have to hack around this ...
|
||||
if (($this->_file_new = ! file_exists($this->_file_path.$session_id)) === TRUE)
|
||||
{
|
||||
if (($this->_file_handle = fopen($this->_file_path.$session_id, 'w+b')) === FALSE)
|
||||
{
|
||||
log_message('error', "Session: File '".$this->_file_path.$session_id."' doesn't exist and cannot be created.");
|
||||
return $this->_failure;
|
||||
}
|
||||
}
|
||||
elseif (($this->_file_handle = fopen($this->_file_path.$session_id, 'r+b')) === FALSE)
|
||||
$this->_file_new = ! file_exists($this->_file_path.$session_id);
|
||||
|
||||
if (($this->_file_handle = fopen($this->_file_path.$session_id, 'c+b')) === FALSE)
|
||||
{
|
||||
log_message('error', "Session: Unable to open file '".$this->_file_path.$session_id."'.");
|
||||
return $this->_failure;
|
||||
@@ -195,7 +207,7 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
}
|
||||
|
||||
$session_data = '';
|
||||
for ($read = 0, $length = filesize($this->_file_path.$session_id); $read < $length; $read += strlen($buffer))
|
||||
for ($read = 0, $length = filesize($this->_file_path.$session_id); $read < $length; $read += self::strlen($buffer))
|
||||
{
|
||||
if (($buffer = fread($this->_file_handle, $length - $read)) === FALSE)
|
||||
{
|
||||
@@ -351,10 +363,13 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
|
||||
$ts = time() - $maxlifetime;
|
||||
|
||||
$pattern = ($this->_config['match_ip'] === TRUE)
|
||||
? '[0-9a-f]{32}'
|
||||
: '';
|
||||
|
||||
$pattern = sprintf(
|
||||
'/^%s[0-9a-f]{%d}$/',
|
||||
preg_quote($this->_config['cookie_name'], '/'),
|
||||
($this->_config['match_ip'] === TRUE ? 72 : 40)
|
||||
'#\A%s'.$pattern.$this->_sid_regexp.'\z#',
|
||||
preg_quote($this->_config['cookie_name'])
|
||||
);
|
||||
|
||||
while (($file = readdir($directory)) !== FALSE)
|
||||
@@ -376,4 +391,34 @@ class CI_Session_files_driver extends CI_Session_driver implements SessionHandle
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate ID
|
||||
*
|
||||
* Checks whether a session ID record exists server-side,
|
||||
* to enforce session.use_strict_mode.
|
||||
*
|
||||
* @param string $id
|
||||
* @return bool
|
||||
*/
|
||||
public function validateId($id)
|
||||
{
|
||||
return is_file($this->_file_path.$id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Byte-safe strlen()
|
||||
*
|
||||
* @param string $str
|
||||
* @return int
|
||||
*/
|
||||
protected static function strlen($str)
|
||||
{
|
||||
return (self::$func_overload)
|
||||
? mb_strlen($str, '8bit')
|
||||
: strlen($str);
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
@@ -145,6 +145,8 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
return $this->_fail();
|
||||
}
|
||||
|
||||
$this->php5_validate_id();
|
||||
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
@@ -186,7 +188,7 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
*/
|
||||
public function write($session_id, $session_data)
|
||||
{
|
||||
if ( ! isset($this->_memcached))
|
||||
if ( ! isset($this->_memcached, $this->_lock_key))
|
||||
{
|
||||
return $this->_fail();
|
||||
}
|
||||
@@ -202,32 +204,25 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
$this->_session_id = $session_id;
|
||||
}
|
||||
|
||||
if (isset($this->_lock_key))
|
||||
$key = $this->_key_prefix.$session_id;
|
||||
|
||||
$this->_memcached->replace($this->_lock_key, time(), 300);
|
||||
if ($this->_fingerprint !== ($fingerprint = md5($session_data)))
|
||||
{
|
||||
$key = $this->_key_prefix.$session_id;
|
||||
|
||||
$this->_memcached->replace($this->_lock_key, time(), 300);
|
||||
if ($this->_fingerprint !== ($fingerprint = md5($session_data)))
|
||||
{
|
||||
if (
|
||||
$this->_memcached->replace($key, $session_data, $this->_config['expiration'])
|
||||
OR ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration']))
|
||||
)
|
||||
{
|
||||
$this->_fingerprint = $fingerprint;
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
return $this->_fail();
|
||||
}
|
||||
|
||||
if (
|
||||
$this->_memcached->touch($key, $this->_config['expiration'])
|
||||
OR ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration']))
|
||||
)
|
||||
if ($this->_memcached->set($key, $session_data, $this->_config['expiration']))
|
||||
{
|
||||
$this->_fingerprint = $fingerprint;
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
return $this->_fail();
|
||||
}
|
||||
elseif (
|
||||
$this->_memcached->touch($key, $this->_config['expiration'])
|
||||
OR ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration']))
|
||||
)
|
||||
{
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
return $this->_fail();
|
||||
@@ -297,6 +292,23 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate ID
|
||||
*
|
||||
* Checks whether a session ID record exists server-side,
|
||||
* to enforce session.use_strict_mode.
|
||||
*
|
||||
* @param string $id
|
||||
* @return bool
|
||||
*/
|
||||
public function validateId($id)
|
||||
{
|
||||
$this->_memcached-get($this->_key_prefix.$id);
|
||||
return ($this->_memcached->getResultCode() === Memcached::RES_SUCCESS);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -317,9 +329,11 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
if ( ! $this->_memcached->replace($this->_lock_key, time(), 300))
|
||||
{
|
||||
return ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND)
|
||||
? $this->_memcached->set($this->_lock_key, time(), 300)
|
||||
? $this->_memcached->add($this->_lock_key, time(), 300)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// 30 attempts to obtain a lock, in case another request already has it
|
||||
@@ -333,7 +347,8 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $this->_memcached->set($lock_key, time(), 300))
|
||||
$method = ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND) ? 'add' : 'set';
|
||||
if ( ! $this->_memcached->$method($lock_key, time(), 300))
|
||||
{
|
||||
log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id);
|
||||
return FALSE;
|
||||
@@ -379,4 +394,4 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
@@ -51,7 +51,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
/**
|
||||
* phpRedis instance
|
||||
*
|
||||
* @var resource
|
||||
* @var Redis
|
||||
*/
|
||||
protected $_redis;
|
||||
|
||||
@@ -153,6 +153,8 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
$this->php5_validate_id();
|
||||
|
||||
return $this->_fail();
|
||||
}
|
||||
|
||||
@@ -199,7 +201,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
*/
|
||||
public function write($session_id, $session_data)
|
||||
{
|
||||
if ( ! isset($this->_redis))
|
||||
if ( ! isset($this->_redis, $this->_lock_key))
|
||||
{
|
||||
return $this->_fail();
|
||||
}
|
||||
@@ -215,27 +217,22 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
$this->_session_id = $session_id;
|
||||
}
|
||||
|
||||
if (isset($this->_lock_key))
|
||||
$this->_redis->setTimeout($this->_lock_key, 300);
|
||||
if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE)
|
||||
{
|
||||
$this->_redis->setTimeout($this->_lock_key, 300);
|
||||
if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE)
|
||||
if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration']))
|
||||
{
|
||||
if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration']))
|
||||
{
|
||||
$this->_fingerprint = $fingerprint;
|
||||
$this->_key_exists = TRUE;
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
return $this->_fail();
|
||||
$this->_fingerprint = $fingerprint;
|
||||
$this->_key_exists = TRUE;
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration']))
|
||||
? $this->_success
|
||||
: $this->_fail();
|
||||
return $this->_fail();
|
||||
}
|
||||
|
||||
return $this->_fail();
|
||||
return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration']))
|
||||
? $this->_success
|
||||
: $this->_fail();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -255,7 +252,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
if ($this->_redis->ping() === '+PONG')
|
||||
{
|
||||
$this->_release_lock();
|
||||
if ($this->_redis->close() === $this->_failure)
|
||||
if ($this->_redis->close() === FALSE)
|
||||
{
|
||||
return $this->_fail();
|
||||
}
|
||||
@@ -315,6 +312,22 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
return $this->_success;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate ID
|
||||
*
|
||||
* Checks whether a session ID record exists server-side,
|
||||
* to enforce session.use_strict_mode.
|
||||
*
|
||||
* @param string $id
|
||||
* @return bool
|
||||
*/
|
||||
public function validateId($id)
|
||||
{
|
||||
return (bool) $this->_redis->exists($this->_key_prefix.$id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -346,7 +359,11 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $this->_redis->setex($lock_key, 300, time()))
|
||||
$result = ($ttl === -2)
|
||||
? $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300))
|
||||
: $this->_redis->setex($lock_key, 300, time());
|
||||
|
||||
if ( ! $result)
|
||||
{
|
||||
log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id);
|
||||
return FALSE;
|
||||
|
Reference in New Issue
Block a user