I'm having a bit of trouble here, and I just can't think straight to get the logic for doing what I need. Here's the situation:
I have a site that lets users log int, but will expire their session automatically after 15 minutes. This expiration will use PHP (because that's what validates the session) to redirect to the login page. I have script in place that does this perfectly.
The problem I'm having is that some data loaded for the user is placed within a <div> on the same page (common practice for sites nowadays).
Here's an example. A user logs in. They go to a "search" page. They are inactive for 15 minutes. When the return, they start typing in the search box. The page send their text to the server and returns the response to the "results" div on the page. However, because they are inactive, the result is that the div is filled with the login page, instead, and this just looks bad.
I tried adding the following code to the login page:
document.location.href = 'login.php';
How can I remedy this? I thought about setting a timeout in my XMLHttpRequest handler that will redirect if required, but I'm wondering if there is a more elegant solution.