summaryrefslogtreecommitdiffstats
path: root/system/libraries/Session.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Session.php')
-rwxr-xr-x[-rw-r--r--]system/libraries/Session.php49
1 files changed, 33 insertions, 16 deletions
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index bd9426818..53ff4f5d3 100644..100755
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -30,6 +30,7 @@ class CI_Session {
var $sess_use_database = FALSE;
var $sess_table_name = '';
var $sess_expiration = 7200;
+ var $sess_expire_on_close = FALSE;
var $sess_match_ip = FALSE;
var $sess_match_useragent = TRUE;
var $sess_cookie_name = 'ci_session';
@@ -38,7 +39,7 @@ class CI_Session {
var $cookie_domain = '';
var $sess_time_to_update = 300;
var $encryption_key = '';
- var $flashdata_key = 'flash';
+ var $flashdata_key = 'flash';
var $time_reference = 'time';
var $gc_probability = 5;
var $userdata = array();
@@ -51,7 +52,7 @@ class CI_Session {
* The constructor runs the session routines automatically
* whenever the class is instantiated.
*/
- function CI_Session($params = array())
+ public function __construct($params = array())
{
log_message('debug', "Session Class Initialized");
@@ -60,11 +61,16 @@ class CI_Session {
// Set all the session preferences, which can either be set
// manually via the $params array above or via the config file
- foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
+ 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', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
{
$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
}
+ if ($this->encryption_key == '')
+ {
+ show_error('In order to use the Session class you are required to set an encryption key in your config file.');
+ }
+
// Load the string helper so we can use the strip_slashes() function
$this->CI->load->helper('string');
@@ -90,7 +96,7 @@ class CI_Session {
{
$this->sess_expiration = (60*60*24*365*2);
}
-
+
// Set the cookie name
$this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name;
@@ -106,10 +112,10 @@ class CI_Session {
}
// Delete 'old' flashdata (from last request)
- $this->_flashdata_sweep();
+ $this->_flashdata_sweep();
// Mark all new flashdata as old (data will be deleted before next request)
- $this->_flashdata_mark();
+ $this->_flashdata_mark();
// Delete expired sessions if necessary
$this->_sess_gc();
@@ -307,9 +313,9 @@ class CI_Session {
$sessid .= $this->CI->input->ip_address();
$this->userdata = array(
- 'session_id' => md5(uniqid($sessid, TRUE)),
- 'ip_address' => $this->CI->input->ip_address(),
- 'user_agent' => substr($this->CI->input->user_agent(), 0, 50),
+ 'session_id' => md5(uniqid($sessid, TRUE)),
+ 'ip_address' => $this->CI->input->ip_address(),
+ 'user_agent' => substr($this->CI->input->user_agent(), 0, 50),
'last_activity' => $this->now
);
@@ -651,11 +657,13 @@ class CI_Session {
$cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key);
}
+ $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();
+
// Set the cookie
setcookie(
$this->sess_cookie_name,
$cookie_data,
- $this->sess_expiration + time(),
+ $expire,
$this->cookie_path,
$this->cookie_domain,
0
@@ -680,12 +688,18 @@ class CI_Session {
{
foreach ($data as $key => $val)
{
- $data[$key] = str_replace('\\', '{{slash}}', $val);
+ if (is_string($val))
+ {
+ $data[$key] = str_replace('\\', '{{slash}}', $val);
+ }
}
}
else
{
- $data = str_replace('\\', '{{slash}}', $data);
+ if (is_string($data))
+ {
+ $data = str_replace('\\', '{{slash}}', $data);
+ }
}
return serialize($data);
@@ -711,13 +725,16 @@ class CI_Session {
{
foreach ($data as $key => $val)
{
- $data[$key] = str_replace('{{slash}}', '\\', $val);
+ if (is_string($val))
+ {
+ $data[$key] = str_replace('{{slash}}', '\\', $val);
+ }
}
return $data;
}
- return str_replace('{{slash}}', '\\', $data);
+ return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
}
// --------------------------------------------------------------------