summaryrefslogtreecommitdiffstats
path: root/system/libraries/Session
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Session')
-rwxr-xr-xsystem/libraries/Session/Session.php16
-rwxr-xr-xsystem/libraries/Session/drivers/Session_cookie.php61
-rwxr-xr-xsystem/libraries/Session/drivers/Session_native.php16
3 files changed, 72 insertions, 21 deletions
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
index 68819a665..41539a598 100755
--- a/system/libraries/Session/Session.php
+++ b/system/libraries/Session/Session.php
@@ -64,7 +64,10 @@ class CI_Session extends CI_Driver_Library {
// Get valid drivers list
$CI =& get_instance();
- $this->valid_drivers = array('Session_native', 'Session_cookie');
+ $this->valid_drivers = array(
+ 'Session_native',
+ 'Session_cookie'
+ );
$key = 'sess_valid_drivers';
$drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key);
if ($drivers)
@@ -116,7 +119,7 @@ class CI_Session extends CI_Driver_Library {
*/
public function load_driver($driver)
{
- // Save reference to most recently loaded driver as library default
+ // Save reference to most recently loaded driver as library default and sync userdata
$this->current = parent::load_driver($driver);
$this->userdata =& $this->current->get_userdata();
return $this->current;
@@ -138,11 +141,13 @@ class CI_Session extends CI_Driver_Library {
$child = str_replace($this->lib_name.'_', '', $driver);
if (isset($this->$child))
{
+ // Make driver current and sync userdata
$this->current = $this->$child;
- $this->userdata =& $this->current->get_userdata();
+ $this->userdata =& $this->current->get_userdata();
}
else
{
+ // Load new driver
$this->load_driver($driver);
}
}
@@ -167,8 +172,9 @@ class CI_Session extends CI_Driver_Library {
*/
public function sess_regenerate($destroy = false)
{
- // Just call regenerate on driver
+ // Call regenerate on driver and resync userdata
$this->current->sess_regenerate($destroy);
+ $this->userdata =& $this->current->get_userdata();
}
/**
@@ -209,7 +215,7 @@ class CI_Session extends CI_Driver_Library {
// if it contains flashdata, add it
if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE)
{
- $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key);
+ $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key);
$out[$key] = $val;
}
}
diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php
index 19ccd417d..8ac92e432 100755
--- a/system/libraries/Session/drivers/Session_cookie.php
+++ b/system/libraries/Session/drivers/Session_cookie.php
@@ -72,7 +72,7 @@ class CI_Session_cookie extends CI_Session_driver {
*
* @var bool
*/
- public $sess_expire_on_close = FALSE;
+ public $sess_expire_on_close = FALSE;
/**
* Whether to match session on ip address
@@ -86,7 +86,7 @@ class CI_Session_cookie extends CI_Session_driver {
*
* @var bool
*/
- public $sess_match_useragent = TRUE;
+ public $sess_match_useragent = TRUE;
/**
* Name of session cookie
@@ -107,7 +107,7 @@ class CI_Session_cookie extends CI_Session_driver {
*
* @var string
*/
- public $cookie_path = '';
+ public $cookie_path = '';
/**
* Session cookie domain
@@ -156,7 +156,7 @@ class CI_Session_cookie extends CI_Session_driver {
*
* @var array
*/
- public $userdata = array();
+ public $userdata = array();
/**
* Reference to CodeIgniter instance
@@ -185,10 +185,25 @@ class CI_Session_cookie extends CI_Session_driver {
// Set all the session preferences, which can either be set
// manually via the $params array or via the config file
- foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration',
- 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path',
- 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix',
- 'encryption_key') as $key)
+ $prefs = array(
+ 'sess_encrypt_cookie',
+ 'sess_use_database',
+ 'sess_table_name',
+ 'sess_expiration',
+ 'sess_expire_on_close',
+ 'sess_match_ip',
+ 'sess_match_useragent',
+ 'sess_cookie_name',
+ 'cookie_path',
+ 'cookie_domain',
+ 'cookie_secure',
+ 'cookie_httponly',
+ 'sess_time_to_update',
+ 'time_reference',
+ 'cookie_prefix',
+ 'encryption_key'
+ );
+ foreach ($prefs as $key)
{
$this->$key = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] :
$this->CI->config->item($key);
@@ -265,7 +280,13 @@ class CI_Session_cookie extends CI_Session_driver {
// Before continuing, we need to determine if there is any custom data to deal with.
// Let's determine this by removing the default indexes to see if there's anything left in the array
// and set the session data while we're at it
- foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
+ $defaults = array(
+ 'session_id',
+ 'ip_address',
+ 'user_agent',
+ 'last_activity'
+ );
+ foreach ($defaults as $val)
{
unset($custom_userdata[$val]);
$cookie_userdata[$val] = $this->userdata[$val];
@@ -285,8 +306,10 @@ class CI_Session_cookie extends CI_Session_driver {
// Run the update query
$this->CI->db->where('session_id', $this->userdata['session_id']);
- $this->CI->db->update($this->sess_table_name,
- array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
+ $this->CI->db->update($this->sess_table_name, array(
+ 'last_activity' => $this->userdata['last_activity'],
+ 'user_data' => $custom_userdata
+ ));
// Write the cookie. Notice that we manually pass the cookie data array to the
// _set_cookie() function. Normally that function will store $this->userdata, but
@@ -535,7 +558,13 @@ class CI_Session_cookie extends CI_Session_driver {
{
// set cookie explicitly to only have our session data
$cookie_data = array();
- foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
+ $defaults = array(
+ 'session_id',
+ 'ip_address',
+ 'user_agent',
+ 'last_activity'
+ );
+ foreach ($defaults as $val)
{
$cookie_data[$val] = $this->userdata[$val];
}
@@ -570,7 +599,13 @@ class CI_Session_cookie extends CI_Session_driver {
{
// set cookie explicitly to only have our session data
$cookie_data = array();
- foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
+ $defaults = array(
+ 'session_id',
+ 'ip_address',
+ 'user_agent',
+ 'last_activity'
+ );
+ foreach ($defaults as $val)
{
$cookie_data[$val] = $this->userdata[$val];
}
diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php
index 27db942eb..356deb4dc 100755
--- a/system/libraries/Session/drivers/Session_native.php
+++ b/system/libraries/Session/drivers/Session_native.php
@@ -36,10 +36,20 @@ class CI_Session_native extends CI_Session_driver {
// Get config parameters
$config = array();
$CI =& get_instance();
- foreach (array('sess_cookie_name', 'sess_expire_on_close', 'sess_expiration', 'sess_match_ip',
- 'sess_match_useragent', 'cookie_prefix', 'cookie_path', 'cookie_domain') as $key)
+ $prefs = array(
+ 'sess_cookie_name',
+ 'sess_expire_on_close',
+ 'sess_expiration',
+ 'sess_match_ip',
+ 'sess_match_useragent',
+ 'cookie_prefix',
+ 'cookie_path',
+ 'cookie_domain'
+ );
+ foreach ($prefs as $key)
{
- $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : $CI->config->item($key);
+ $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] :
+ $CI->config->item($key);
}
// Set session name, if specified