I am looking for a jQuery plugin that can display a timer with miliseconds and also return that time to save a highscore. does anyone know a good one? It should also at least try to avoid cheating.
Thanks
I think that to make a tamper-proof timer, it is not enough to use a client-side JS plugin, you will have to check the time on the server. For example, send an AJAX request on start and on finish and measure the time between them.
As for the clock plugin, you can for example use epiclock, but do not rely on it to measure the time.
Related
i need your help.
I need to make a real time timer in my webpage, but i need to operate it from backend (ex like start stop or reset).
Can anyone help me?, i didnt have any idea to make this thing
Sorry for my bad english.
thanks.
ps : the timer's time is same in all of users
ps : the timer's time is same in all of users
this would not be easy.
When admin start/pause/resume/stop timer. all client timer will started.
realtime
prevent bunch of request to server.
javascript only is not possible to doing this. if you are using javascript to check every certain time (setInterval), this will hard for server
to make this happens, i recommend you to use https://socket.io/
example: realtime chat, realtime notification is using websocket
good luck
You want something like this?
How to create a JQuery Clock / Timer
This takes your date/time, and after every second it updates your time on the screen.
I am currently making a timer in javascript and I want to make sure that if you close the browser that its not just lost...so as my clock is ticking away I am storing a cookie every 100ms.
It's every 100ms as I am using the system time instead of just a system interval so I am basically just calculating the difference in time between the start and now and just want to update that as nicely as possible.
I could reduce it to 500ms I guess but its still basically doing the same thing...
I'm just wondering if storing cookies this way is a bad thing in any way and if it is a bad thing is there a better way to be doing this?
Cheers!
I am not sure what the "big picture" is, but here is my take on it.
If your web page is showing a count-down to a certain event, I would split the responsibility between server side code and client side.
On page-load get data from the server on time-remaining and start the timer. No need to store anything in cookies. On page-load, you can get the data from the server again, so nothing is lost.
I want to measure the time it takes for a user to complete a task (answer a quiz). I want to measure it accurately, without the network lag. Meaning, if I measure on the server side the time between 2 requests, it won't be the real time it took the user, because the network time is factored in.
But on the other hand, if I measure in javascript and post the timestamps to the server, the user will be able to see the code, and cheat by sending false timestamps, no?
How can I get the timestamps in javascript and make sure the user doesn't fake it?
Generally in client side code, any question that starts off with "How to securely..." is answered with "Not possible". Nothing, not even putting variables in a closure (because I, the evil cheating user could just change the code on my end and send it back to you).
This is the kind of validation that should be performed server side, even with the disadvantage of network latency.
The trick here would be to measure the time using JavaScript, but also keep track of it using server-side code. That way, you can rely on the timestamps received by the client as long as you enforce a maximum difference between calculated times. I'd say a few seconds should be good enough. However, by doing so, you are creating an additional vector for failure.
Edit: A user could potentially tweak his or her time in their favor by up to the maximum enforced difference if they are able to take advantage of the (lack of) network lag.
I faced same problem while designing an online examination portal for my project.
I went for a hybrid approach.
Get time from server as user loads the page, and starts timer based on javascript. Record the start time in your database.
Let the timer run on client side for some time, say 30 seconds.
Refresh timer by making a AJAX call to server for timer reset as per the time that has passed already.
NOTE: try to use external javascript and obfuscate the code of timer to make guessing difficult.
This way you may not prevent user completely from modifying timer, but you can limit max possible error to 30s.
I have php file, that generates json with a countdown seconds to the New Year eve and to some birthdays. But I want the countdown to change every one second. Is it safe (will it overload the server) if I setTimeout(1000) to my ajax call function?
And what's the best way to implement 1 second JSON call via jQuery?
Thank you
Instead of overloading your server with requests (take into context you might have many users doing many requests at once coupled to your constants callbacks), take your data all at once for the following day for example and process the birthdays only in javascript.
The only Ajax portion i'd use in there would be to load more birthdays once per hour or day in case you have a really hyped user that leave his browser open.
The load on the server depends on:
The amount of work the php does each time it is called
and
The number of users you expect
Depending on what the server is doing, you may well be able to move the countdown logic into the client javascript, with the server just calculating the initial values. You can then use a timer in javascript to update every second, calculating the difference between the current time and the starting values.
Depends on your server and how optimised your PHP endpoint is... its a very conditional question.
However for what your doing, I would also suggest doing it all from JS.. even with birthdays, I would set a JSON object in the markup with all the birthdays that are recorded, then you can do it all client side... maybe call ajax every 5-10 minutes for any new birthdays that may be added... depends on what your application is.
I used setInterval, and checked if the remaining time equals zero. Then I rerun the ajax function.
thank you, all :) you were helpful after all ;)
if I understand, you want to call your server every second to update your time.
Can't you just :
Call your server to get the actual time
List item 2 - Process with a JS setInterval(functionIncrementAndUpdateDate, 1000); ?
You could use Keith Wood's countdown timer: http://keith-wood.name/countdown.html
It is extremely easy to use and no need for AJAX. All you have to do is include the plugin file and write:
<div id="timer"></div>
$(document).ready(function() {
$('#timer').countdown({
until: '<?php echo date("h:i:s"); ?>' // change this to New Year or a Birthday from DB
});
});
Demo: http://jsfiddle.net/tqyj4/436/
If I make a live countdown clock like ebay, how do I do this with django and sql? I'm assuming running a function in django or in sql over and over every second to check the time would be horribly inefficient.
Is this even a plausible strategy?
Or is this the way they do it:
When a page loads, it takes the end datetime from the server and runs a javascript countdown clock against it on the user machine?
If so, how do you do the countdown clock with javascript? And how would I be able to delete/move data once the time limit is over without a user page load? Or is it absolutely necessary for the user to load the page to check the time limit to create an efficient countdown clock?
I don't think this question has anything to do with SQL, really--except that you might retrieve an expiration time from SQL. What you really care about is just how to display the timeout real-time in the browser, right?
Obviously the easiest way is just to send a "seconds remaining" counter to the page, either on the initial load, or as part of an AJAX request, then use Javascript to display the timer, and update it every second with the current value. I would opt for using a "seconds remaining" counter rather than an "end datetime", because you can't trust a browser's clock to be set correctly--but you probably can trust it to count down seconds correctly.
If you don't trust Javascript, or the client's clock, to be accurate, you could periodically re-send the current "seconds remaining" value to the browser via AJAX. I wouldn't do this every second, maybe every 15 or 60 seconds at most.
As for deleting/moving data when the clock expires, you'll need to do all of that in Javascript.
I'm not 100% sure I answered all of your questions, but your questions seem a bit scattered anyway. If you need more clarification on the theory of operation, please ask.
I have also encountered the same problem a while ago.
First of all your problem is not related neither django nor sql. It is a general concept and it is not very easy to implement because of overhead in server.
One solution come into my mind is keeping start time of the process in the database.
When someone request you to see remaingn time, read it from database, subtract the current time and server that time and in your browser initialize your javascript function with that value and countdown like 15 sec. After that do the same operation with AJAX without waiting user's request.
However, there would be other implementations depending your application. If you explain your application in detail there could be other solutions.
For example, if you implement a questionnaire with limited time, then for every answer submit, you should pass the calculated javascript value for that second.