Created
February 5, 2012 10:53
-
-
Save keiya/1744719 to your computer and use it in GitHub Desktop.
CodeIgniter Session Lightweight Patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- Session_orig.php 2012-02-05 17:59:53.655951256 +0900 | |
| +++ Session.php 2012-02-05 18:09:07.779674380 +0900 | |
| @@ -21,7 +21,7 @@ | |
| * @package CodeIgniter | |
| * @subpackage Libraries | |
| * @category Sessions | |
| - * @author ExpressionEngine Dev Team | |
| + * @author ExpressionEngine Dev Team & Keiya Chinen <[email protected]> | |
| * @link http://codeigniter.com/user_guide/libraries/sessions.html | |
| */ | |
| class CI_Session { | |
| @@ -31,8 +31,6 @@ | |
| 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'; | |
| var $cookie_prefix = ''; | |
| var $cookie_path = ''; | |
| @@ -62,7 +60,7 @@ | |
| // 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_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', '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_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) | |
| { | |
| $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); | |
| } | |
| @@ -168,7 +166,7 @@ | |
| $session = $this->_unserialize($session); | |
| // Is the session data we unserialized an array with the correct format? | |
| - if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity'])) | |
| + if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['last_activity'])) | |
| { | |
| $this->sess_destroy(); | |
| return FALSE; | |
| @@ -181,35 +179,11 @@ | |
| return FALSE; | |
| } | |
| - // Does the IP Match? | |
| - if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) | |
| - { | |
| - $this->sess_destroy(); | |
| - return FALSE; | |
| - } | |
| - | |
| - // Does the User Agent Match? | |
| - if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120))) | |
| - { | |
| - $this->sess_destroy(); | |
| - return FALSE; | |
| - } | |
| - | |
| // Is there a corresponding session in the DB? | |
| if ($this->sess_use_database === TRUE) | |
| { | |
| $this->CI->db->where('session_id', $session['session_id']); | |
| - if ($this->sess_match_ip == TRUE) | |
| - { | |
| - $this->CI->db->where('ip_address', $session['ip_address']); | |
| - } | |
| - | |
| - if ($this->sess_match_useragent == TRUE) | |
| - { | |
| - $this->CI->db->where('user_agent', $session['user_agent']); | |
| - } | |
| - | |
| $query = $this->CI->db->get($this->sess_table_name); | |
| // No result? Kill it! | |
| @@ -266,7 +240,7 @@ | |
| // 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) | |
| + foreach (array('session_id','last_activity') as $val) | |
| { | |
| unset($custom_userdata[$val]); | |
| $cookie_userdata[$val] = $this->userdata[$val]; | |
| @@ -315,8 +289,6 @@ | |
| $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, 120), | |
| 'last_activity' => $this->now, | |
| 'user_data' => '' | |
| ); | |
| @@ -376,7 +348,7 @@ | |
| { | |
| // set cookie explicitly to only have our session data | |
| $cookie_data = array(); | |
| - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) | |
| + foreach (array('session_id','last_activity') as $val) | |
| { | |
| $cookie_data[$val] = $this->userdata[$val]; | |
| } | |
| @@ -774,4 +746,4 @@ | |
| // END Session Class | |
| /* End of file Session.php */ | |
| -/* Location: ./system/libraries/Session.php */ | |
| \ No newline at end of file | |
| +/* Location: ./system/libraries/Session.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment