@@ -334,12 +334,40 @@ public function sess_create()
334
334
public function sess_update ()
335
335
{
336
336
// We only update the session every five minutes by default
337
- if (($ this ->userdata ['last_activity ' ] + $ this ->sess_time_to_update ) >= $ this ->now
338
- OR $ this ->CI ->input ->is_ajax_request ()) // Changing the session ID during an AJAX call causes problems
337
+ if (($ this ->userdata ['last_activity ' ] + $ this ->sess_time_to_update ) >= $ this ->now )
339
338
{
340
339
return ;
341
340
}
342
341
342
+ // _set_cookie() will handle this for us if we aren't using database sessions
343
+ // by pushing all userdata to the cookie.
344
+ $ cookie_data = NULL ;
345
+
346
+ /* Changing the session ID during an AJAX call causes problems,
347
+ * so we'll only update our last_activity
348
+ */
349
+ if ($ this ->CI ->input ->is_ajax_request ())
350
+ {
351
+ $ this ->userdata ['last_activity ' ] = $ this ->now ;
352
+
353
+ // Update the session ID and last_activity field in the DB if needed
354
+ if ($ this ->sess_use_database === TRUE )
355
+ {
356
+ // set cookie explicitly to only have our session data
357
+ $ cookie_data = array ();
358
+ foreach (array ('session_id ' ,'ip_address ' ,'user_agent ' ,'last_activity ' ) as $ val )
359
+ {
360
+ $ cookie_data [$ val ] = $ this ->userdata [$ val ];
361
+ }
362
+
363
+ $ this ->CI ->db ->query ($ this ->CI ->db ->update_string ($ this ->sess_table_name ,
364
+ array ('last_activity ' => $ this ->userdata ['last_activity ' ]),
365
+ array ('session_id ' => $ this ->userdata ['session_id ' ])));
366
+ }
367
+
368
+ return $ this ->_set_cookie ($ cookie_data );
369
+ }
370
+
343
371
// Save the old session id so we know which record to
344
372
// update in the database if we need it
345
373
$ old_sessid = $ this ->userdata ['session_id ' ];
@@ -357,10 +385,6 @@ public function sess_update()
357
385
$ this ->userdata ['session_id ' ] = $ new_sessid = md5 (uniqid ($ new_sessid , TRUE ));
358
386
$ this ->userdata ['last_activity ' ] = $ this ->now ;
359
387
360
- // _set_cookie() will handle this for us if we aren't using database sessions
361
- // by pushing all userdata to the cookie.
362
- $ cookie_data = NULL ;
363
-
364
388
// Update the session ID and last_activity field in the DB if needed
365
389
if ($ this ->sess_use_database === TRUE )
366
390
{
0 commit comments