View Full Version : Persistent JS/PHP Countdown Timer

03-16-2007, 12:32 AM
I have coded a JS countdown timer which is all good and fine if the users continues to view the page.

But how would I create a (fairly secure) countdown timer which includes PHP based server-side checks so that if the user leaves the page and then returns to the page the countdown timer continues uninterrupted?

I was thinking about writing a PHP app to do this.. but I am honestly unsure about the best way to go about this... any ideas please?

I don't want to use cookies, by the way, since they are less secure. It has to be JS/PHP based (I am using mySQL as my db).

I ask because I am making a little web game where the user builds units (like an RTS) .. if he/she clicks "build" the 2 minute countdown timer starts, he can then surf to different pages and then when he/she comes back the countdown timer will continue to countdown

03-16-2007, 02:48 PM

03-16-2007, 02:51 PM
Can only think of an AJAX solution for this, but will be heavy on server resources - as it'll query every second or so

03-16-2007, 06:06 PM
When they click Build store the time in the database and start the JS timer. Then when they either come back, refresh the page, or the timer runs out(have it refresh the page) make sure that 2 minutes had passed since they started building.