summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-01-19 13:12:54 +0100
committerAndrey Andreev <narf@bofh.bg>2012-01-19 13:12:54 +0100
commit9c622f373046a0a626799f4ed5a0f944628b0b43 (patch)
tree81e9cdf30dcb4a965dd8e3314a7f3366e41b27c0 /system
parenteea2ff56657dc5f690523cfcd372b760569ef649 (diff)
Still update the session on AJAX calls, just don't regenerate the session ID
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Session.php36
1 files changed, 30 insertions, 6 deletions
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index c4f97e965..784bb62b2 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -334,12 +334,40 @@ class CI_Session {
public function sess_update()
{
// We only update the session every five minutes by default
- if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now
- OR $this->CI->input->is_ajax_request()) // Changing the session ID during an AJAX call causes problems
+ if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
{
return;
}
+ // _set_cookie() will handle this for us if we aren't using database sessions
+ // by pushing all userdata to the cookie.
+ $cookie_data = NULL;
+
+ /* Changing the session ID during an AJAX call causes problems,
+ * so we'll only update our last_activity
+ */
+ if ($this->CI->input->is_ajax_request())
+ {
+ $this->userdata['last_activity'] = $this->now;
+
+ // Update the session ID and last_activity field in the DB if needed
+ if ($this->sess_use_database === TRUE)
+ {
+ // set cookie explicitly to only have our session data
+ $cookie_data = array();
+ foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
+ {
+ $cookie_data[$val] = $this->userdata[$val];
+ }
+
+ $this->CI->db->query($this->CI->db->update_string($this->sess_table_name,
+ array('last_activity' => $this->userdata['last_activity']),
+ array('session_id' => $this->userdata['session_id'])));
+ }
+
+ return $this->_set_cookie($cookie_data);
+ }
+
// Save the old session id so we know which record to
// update in the database if we need it
$old_sessid = $this->userdata['session_id'];
@@ -357,10 +385,6 @@ class CI_Session {
$this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, TRUE));
$this->userdata['last_activity'] = $this->now;
- // _set_cookie() will handle this for us if we aren't using database sessions
- // by pushing all userdata to the cookie.
- $cookie_data = NULL;
-
// Update the session ID and last_activity field in the DB if needed
if ($this->sess_use_database === TRUE)
{