I have setInterval implemented with JQuery to update a div within a protected page. When the session for this part of the site expires, the user is taken back to the public side of the site. This action only occurs if the user clicks a link that refreshes that page.
The issue that I’m having is that careless users are not logging out and setInterval continues its attempts to update the div thus creating a huge access log file in Apache. (> 12Mb per day) setInterval continues its attempt to update because even though the session is dead, the page is not refreshing so setInterval keeps going.
Is there a way to kill setInterval after a certain amount of time? Say 12 hours or so.
Yes there is, the setTimeout function returns a timerID that you can use to kill the timer by calling clearTimeout. However setTimeout is only occures once and they are automatically cancelled when the user navigates away from the page. (are you using frames, because otherwise this shouldn’t be an issue)
I suggest using a less verbose method and rely on AJAX and a session context to detect when the user is no longer being active and simply log them out automatically.