Search code examples
javascripttimercountdown

Countdown seconds, update database and loop the Countdown


i'm trying to do a small countdown script only in seconds that update my database when it reaches 0 and start the countdown process again.

Example:

HTML

<p>Updating your profile in <span class="countdown"></span> seconds.</p>

I need the profile to be updated every 780 seconds, once the countdown reaches 0 it makes a ajax call to update the profile and resets the countdown to repete all over again.

Also i've tryed some countdown scripts but the user can change the script in browser, is there any possibility to protect the website from users changing the code?

Thanks


Solution

  • Im making a website for a friend of mine that streams, and he wants to give hes viewers points every lets say 780seconds (10 minutes) so they can spend them to earn giveaways... so i need the script to start a countdown on pageload and repete every 780 seconds and update the database..

    This is more a security question it seems to me. You're wondering how you can securely track timed events on the client.

    You confront some problems: anyone who knows how can change the code to make the AJAX call more often (thereby giving them more points) so client side isn't feasible, but neither can you can track user interaction with your page through server side code alone.

    So I think what you want is a combination of both. You want periodic ajax calls on the client side, but you want to verify the timing based on some code the server side - you probably want to send AJAX calls, but verify the timing and the user identity by checking a session or cookie id.