CodeIgniter Forums
Any way to force sessions to *not* update on certain AJAX requests? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Any way to force sessions to *not* update on certain AJAX requests? (/thread-67014.html)



Any way to force sessions to *not* update on certain AJAX requests? - twistedpixel - 01-02-2017

Hi all,

I'm a fairly experienced CI dev but I'm having trouble finding a good solution for this.

Essentially, I'm trying to implement "idle logout" (session expiration) detection. I'd like to be able to periodically make an AJAX call to check if the current session entry still contains credentials but by making these AJAX calls, the session is updated automatically to extend its validity (indefinitely!).

Has anyone found a way to do this?

Cheers!


RE: Any way to force sessions to *not* update on certain AJAX requests? - InsiteFX - 01-02-2017

Did you read and try this?

CodeIgniter Users Guide - Session Library - A note about concurrency


RE: Any way to force sessions to *not* update on certain AJAX requests? - twistedpixel - 01-02-2017

Thanks InsiteFX, but I don't think that's quite the problem. Unless I'm misunderstanding? It's not that AJAX requests are blocking/interfering, it's that I'd like to skip the auto-update of sessions on specific AJAX requests.

Please feel free to correct me if I've missed the point you were making.


RE: Any way to force sessions to *not* update on certain AJAX requests? - InsiteFX - 01-03-2017

The only other thing that CI has for Ajax is this:

is_ajax_request()

You may need to extend the library to suit your needs.


RE: Any way to force sessions to *not* update on certain AJAX requests? - twistedpixel - 01-03-2017

Sadly I think you're right. I was hoping for a less arduous solution but I guess extending the Session Library is the only option.

Cheers anyway!


RE: Any way to force sessions to *not* update on certain AJAX requests? - Narf - 01-03-2017

@InsiteFX ...

You're doing it yet again.
You see "Session" and just paste the link to something else mentioning "session".
This doesn't help.

@twistedpixel

You can put a counter in sync with the session cookie.


RE: Any way to force sessions to *not* update on certain AJAX requests? - twistedpixel - 02-01-2017

(01-03-2017, 06:51 AM)Narf Wrote: @InsiteFX ...

You're doing it yet again.
You see "Session" and just paste the link to something else mentioning "session".
This doesn't help.

@twistedpixel

You can put a counter in sync with the session cookie.

Sorry, for some reason I didn't get a notification of a reply here. Actually Narf, that's exactly what I ended up doing (as the second half of the issue you gave me advice on earlier). Works beautifully.