CakePHP redirect a user after idle for a preset length of time

When a user is on my site for x minutes I want them to get redirected to a different page on the site.  A user logs into the site and winds up on the homepage, if they sit there to long I want to redirect them to a temporary page to reduce the load on the server.  Is there an easy way to implement this in CakePHP?  Currently I am using a lot of AJAX on the homepage to interact with the site and would like to implement it within those calls already being made.  Any ideas on this would be helpful as I am stuck.  I can make it work, but it is only working after the session expires and the person goes to another page.  I want it to work automatically based on them being idle on one page and separate from the session time.
LVL 4
termlimitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

v2MediaCommented:
How about a Javascript solution? Since this concerns client side activity, it needs a client side solution:-
var idleTime    = 20*60*60*1000; /*20 minutes in milliseconds*/
var timeOut     = '';
var redirectURL = 'http://www.domain.com/page.html';

function init() {
    
    Event.observe(document.body, ‘mousemove’, resetIdle, true);   
    setIdle();   
}

function onIdleFunction(){
   
    window.location.href=redirectURL;       
}

function resetIdle(){
   
    window.clearTimeout( timeOut );
    setIdle();   
}

function setIdle(){
   
    timeOut = window.setTimeout( "onIdleFunction()", idleTime );   
}

Event.observe(window, ‘load’, init, false);

Open in new window

0
termlimitAuthor Commented:
Thanks for the response.  So far all I am getting in response is:
"Event.observe is not a function"

Any ideas?
0
v2MediaCommented:
Sorry - should have mentioned Event.observe uses the protptype library. You can download it here:-

http://www.prototypejs.org/download

Script was written with 1.5.0 version. Download it and include it on your webpages.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

termlimitAuthor Commented:
Is there any way to do this without the prototype library?
0
termlimitAuthor Commented:
I added in prototype (1.5.0) from the download page you provided.  I made sure that i uploaded it and pointed to the file, before making the call you pasted above.  It is still throwing the same error as before.  It is also breaking the rest of my JavaScript that I have on the page from my current program.  Any way to do this without prototype?
0
v2MediaCommented:
What js libraries/frameworks are you currently using on the site?
0
termlimitAuthor Commented:
jquery
fckeditor
0
v2MediaCommented:
I'll check out jQuery for a similar method. What version u using?
0
termlimitAuthor Commented:
jQuery 1.2.6 - New Wave Javascript
0
termlimitAuthor Commented:
o and thanks again!
0
termlimitAuthor Commented:
Here is what I came up with.  The problem with it though is that at the timeout amount it is redirecting regardless of mouse movement or not.  I want the timer to reset every time a user moves their mouse.  So at 5 minutes in I move my mouse, it should reset and give me 10 more minutes.
<script type="text/javascript">
	/*var idleTime    = 1*60*60*1000; /*20 minutes in milliseconds*/
	var idleTime	= 900000;
	var timeOut     = '';
	var redirectURL = 'http://www.bidash.com/page/idle';

	function inac() {
		$(document).bind('onmousemove', resetIdle);
		setIdle();
	}

	function onIdleFunction(){
		window.location='/page/idle';
	}

	function resetIdle(){
		window.clearTimeout( timeOut );
		setIdle();
	}

	function setIdle(){
		timeOut = window.setTimeout( "onIdleFunction()", idleTime );
	}

	window.onload = inac;
</script>

Open in new window

0
v2MediaCommented:
Can you chuck up a link? There's probably a conflict happening..
0
termlimitAuthor Commented:
Sorry so late getting back to you.  It is a private development server on a closed intranet.  I am thinking that it might be the inac() call also calling the setIdle().  Should that be in there?  Or is the way that I converted it not properly making the timer reset?  I have firebug installed and I can get you any information you need from there.
0
v2MediaCommented:
How about including the script just before the closing </body> tag and changing

window.onload = inac;

to just

inac();

(purge browser cache before testing)

I'm hoping the conflict is with the window.onload. If that doesn't work, posting the debug output from firefox's js debugger would be handy.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
termlimitAuthor Commented:
I put it just before the </body> tag, changed window.onload = inac; to inac();, and cleared my cache, but I got the same result.  No errors are being thrown by the debugger.  I will try and put it up on a public ftp site for you to look at on a blank page to see if that works at least.

OK here is a test page.  Just this script is running and the mousemove is not registering.
http://www.elementmediadesign.com/test/default.php

I have it set to 9 seconds so you can see the effect without waiting 10 minutes.
0
termlimitAuthor Commented:
Wow completely messed that up!  So the line that I did the bind in, I changed it to the JS call of onmousemove, but it should be mousemove.  I changed that and it was all fixed!  Thanks a lot.  I appreciate the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.