Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    Persistent JS/PHP Countdown Timer

    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

  • #2
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    anyone?

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Can only think of an AJAX solution for this, but will be heavy on server resources - as it'll query every second or so

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •