Saman Gholami
Saman Gholami

Reputation: 3512

php Server side timer Independent of client browser

i need a timer that works like this :

imagine somebody have a limit time to do some actions, i can implement js and client side code,but if the client closes the browser or my page,the timer will unloaded. i need something that runs Independent of client action.. help me... thanks...

Upvotes: 1

Views: 814

Answers (2)

alexwells
alexwells

Reputation: 1253

You could save the start time in a database with an id attached to it. Then store that id in a cookie that expires long after your timer does in the client's browser. That way you can keep track of the start time even if they close their browser. (But they could still delete the cookie).

When they send in a request use the cookie to lookup the start time from the database and take action if their time has expired.

If you need to process the timer even if the user doesn't send in another request to the server you could set up a cron job that looks at the database for expired timers.

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324800

Save the time at which the action was started, then when the client submits the result check against the saved time to see how long it took. If it took too long, do something about it.

Upvotes: 1

Related Questions