From e2afc886d5e7fe1d55a467c9bc46fe40c1a2bbf6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 01:35:34 +0200 Subject: Session cookie driver changes - Changed docs CREATE TABLE ci_sessions example to have the PRIMARY KEY of session_id, ip_address and user_agent combined. - Changed DB updates to add WHERE clauses for the ip_address and/or user_agent strings if sess_match_ip and/or sess_match_useragent are set to TRUE. --- .../libraries/Session/drivers/Session_cookie.php | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'system/libraries/Session') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 2f1bf3531..8f527ace7 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -540,11 +540,25 @@ class CI_Session_cookie extends CI_Session_driver { // Check for database if ($this->sess_use_database === TRUE) { + $this->CI->db->where('session_id', $old_sessid); + + if ($this->sess_match_ip === TRUE) + { + $this->CI->db->where('ip_address', $this->CI->input->ip_address()); + } + + if ($this->sess_match_useragent === TRUE) + { + $this->CI->db->where('user_agent', trim(substr($this->CI->input->user_agent(), 0, 120))); + } + // Update the session ID and last_activity field in the DB - $this->CI->db->update($this->sess_table_name, array( - 'last_activity' => $this->now, - 'session_id' => $this->userdata['session_id'] - ), array('session_id' => $old_sessid)); + $this->CI->db->update($this->sess_table_name, + array( + 'last_activity' => $this->now, + 'session_id' => $this->userdata['session_id'] + ) + ); } // Write the cookie @@ -590,7 +604,19 @@ class CI_Session_cookie extends CI_Session_driver { // Run the update query // Any time we change the session id, it gets updated immediately, // so our where clause below is always safe - $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id'])); + $this->CI->db->where('session_id', $this->userdata['session_id']); + + if ($this->sess_match_ip === TRUE) + { + $this->CI->db->where('ip_address', $this->CI->input->ip_address()); + } + + if ($this->sess_match_useragent === TRUE) + { + $this->CI->db->where('user_agent', trim(substr($this->CI->input->user_agent(), 0, 120))); + } + + $this->CI->db->update($this->sess_table_name, $set); // Clear dirty flag to prevent double updates $this->data_dirty = FALSE; -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Session/Session.php | 5 +++-- system/libraries/Session/drivers/Session_cookie.php | 5 +++-- system/libraries/Session/drivers/Session_native.php | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'system/libraries/Session') diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index fec9b5b31..fb5b9fdd3 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -1,4 +1,4 @@ - Date: Thu, 1 Nov 2012 23:33:14 +0200 Subject: [ci skip] DocBlocks for Pagination, Session, Trackback, Jquery libraries Partially fixes issue #1295 --- system/libraries/Session/Session.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'system/libraries/Session') diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index fb5b9fdd3..bb13c3376 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -52,10 +52,29 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_Session extends CI_Driver_Library { + /** + * Initialization parameters + * + * @var array + */ public $params = array(); + + /** + * Current driver in use + * + * @var string + */ protected $current = NULL; + + /** + * User data + * + * @var array + */ protected $userdata = array(); + // ------------------------------------------------------------------------ + const FLASHDATA_KEY = 'flash'; const FLASHDATA_NEW = ':new:'; const FLASHDATA_OLD = ':old:'; @@ -63,6 +82,8 @@ class CI_Session extends CI_Driver_Library { const EXPIRATION_KEY = '__expirations'; const TEMP_EXP_DEF = 300; + // ------------------------------------------------------------------------ + /** * CI_Session constructor * @@ -596,8 +617,16 @@ class CI_Session extends CI_Driver_Library { */ abstract class CI_Session_driver extends CI_Driver { + /** + * CI Singleton + * + * @see get_instance() + * @var object + */ protected $CI; + // ------------------------------------------------------------------------ + /** * Constructor * -- cgit v1.2.3-24-g4f1b From e24eed7e4e410fabf7479a67d3a27e2596444505 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 23:33:45 +0200 Subject: Some micro-optimizations --- system/libraries/Session/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Session') diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index bb13c3376..96e65f154 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -528,7 +528,7 @@ class CI_Session extends CI_Driver_Library { foreach ($this->all_userdata() as $name => $value) { $parts = explode(self::FLASHDATA_NEW, $name); - if (is_array($parts) && count($parts) === 2) + if (count($parts) === 2) { $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1]; $this->set_userdata($new_name, $value); -- cgit v1.2.3-24-g4f1b