Welcome Guest, Not a member yet? Register   Sign In
Ajax and Session loss
#1

[eluser]kenjis[/eluser]
CI's default 5 min session updating can cause session loss when more than 2 requests come at the same time, most of cases with Ajax calls.

Many people get stuck to this issue.

http://ellislab.com/forums/viewthread/167310/
http://ellislab.com/forums/viewthread/102456/

How about stopping session update in case Ajax call?

Code:
--- a/system/libraries/Session.php    Tue Sep 14 18:45:42 2010 -0500
+++ b/system/libraries/Session.php    Wed Sep 15 10:02:06 2010 +0900
@@ -340,6 +340,12 @@
      */
     function sess_update()
     {
+        // Skip the session update in case Ajax call
+        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
+        {
+            return;
+        }
+
         // We only update the session every five minutes by default
         if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
         {

Note: You need to send X_REQUESTED_WITH header manually if you use jQuery or so.


Messages In This Thread
Ajax and Session loss - by El Forum - 09-14-2010, 07:09 PM
Ajax and Session loss - by El Forum - 09-14-2010, 10:41 PM
Ajax and Session loss - by El Forum - 09-14-2010, 11:00 PM
Ajax and Session loss - by El Forum - 09-14-2010, 11:12 PM
Ajax and Session loss - by El Forum - 09-14-2010, 11:13 PM
Ajax and Session loss - by El Forum - 05-12-2011, 05:33 PM
Ajax and Session loss - by El Forum - 05-12-2011, 07:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB