I was hoping to pick people's brains on a topic. I am developing a web app which sits on top of Expression Engine and this has worked really well so far.

I have one issue though and I have a quick solution but I was hoping to find a more elegant approach, perhaps using hooks or something of that nature.

Basically, our application is very heavily ajax-driven and as such our users can do quite a lot without ever really leaving the page. However, they need to be logged in to do this properly. So you can imagine a scenario whereby a user walks away from their computer for an extended period, comes back, sees the application still running and then attempts to work with it but finds that they either experience erratic behaviour or else nothing works.

Obviously I can set up a template somewhere which would return whether or not the user is logged in or if there is an active session, however this would then involve me either continuously checking that template via an ajax call or else checking the template before I process any other calls. So I'm just wondering if there is a way to kick the user out or redirect them to the login page when a session ends or something similar?

I want to avoid any unnecessary calls to templates, etc. so ideally there will be a more elegant approach out there, or even an existing module or extension. I have plenty of experience in developing third_party add-ons for EE so that's not an issue. Just looking for ideas really :)

Thanks in advance, Conor

  • 1
    could you add some data to the end of your existing ajax requests that would only exist if a member was logged in (like a member_id) and then redirect if it doesn't exist?
    – mjr
    Feb 28, 2013 at 22:30
  • mjr, if I were to adopt that methodology, surely I would be using something like a js variable? If thats the case then I would have the same issue because I have no way in js of checking my logged_in status and updating the value of that variable without continuously calling ajax requests or otherwise Mar 1, 2013 at 0:05
  • 1
    hmm, can you set a timer in your js, any action by the user would reset the timer, and the timer could be equal to or less than your php session length?
    – mjr
    Mar 1, 2013 at 4:18

1 Answer 1


Like MJR suggest, set a javascript timer to about the same length as the logout / session-expiration timer. Then redirect after timeout.

The elegant part: Around 20 or 30 secs before expiration, popup a dialog that the session is about to expire.

(maybe redirect to a page where the user is going to be logged out, to prevent redirecting without the session actually being expired).

  • I would make the value of the JS timer a bit less than the ExpressionEngine timer, just to err on the safe side.
    – Tim
    Mar 14, 2013 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.