Search code examples
phpjquerycountdown

How to prevent timer reset on page refresh?


I'm using jQuery countdown in a script, but I can't figure out how to prevent the timer from resetting on a page reload. I'm hoping someone knows how or can give me a suggestion? I'm using PHP, so I thought maybe at some point I can add a variable to a $_SESSION, but is that enough?


Solution

  • If you want to persist a count value from one page to the next, you will have to store the current counter somewhere before the page refresh and read it back in from the new page and initialize your counter with the saved value. The classic place to store something like that would be in a cookie, but you could also store it in HTML5 local storage (newer browsers only) or by passing it in a query parameter when loading the new page.

    Since the counter is a client-side counter, I'm not sure how you could use a server session to help you.