Solved

jQuery CountDown time-limit strange variations...

Posted on 2010-08-30
18
932 Views
Last Modified: 2012-05-10
Hi there,

I store the exact (server) time each user "starts" a test in a SQLserver database, then I add 40minutes to create the timeLimit for the user to FINISH his/her test.

The following code is the "until"  JQuery CountDown feature, EXACTLY as it is developed.

It seems to work fine, BUT WHEN I test the 40minute time-limit in many different computers, in some of them the counter starts at 39min40seconds, in others it starts at 38min20seconds... you got the picture...

Question: what is going on?  Why the server-time (FIXED) is not "enough" to garantee that all users will have exactly 40minutes to do their test?

Thanks!
fskilnik.
<script type="text/javascript">

$(function () {



	$('#defaultCountdown').countdown({ format: 'MS', compact: false, 

	                                   expiryUrl: "http://www.mysite.com/closingPage.html", 

      until: new Date(<%=(rsParsingTimes.Fields.Item("YearLimit").Value)%>, 

		   <%=(rsParsingTimes.Fields.Item("MonthLimit").Value)%>-1 , 

     	            <%=(rsParsingTimes.Fields.Item("DayLimit").Value)%>, 

	            <%=(rsParsingTimes.Fields.Item("HourLimit").Value)%>, 

    	            <%=(rsParsingTimes.Fields.Item("MinuteLimit").Value)%>,0,0), 

   timezone: -3});



});

</script>

Open in new window

0
Comment
Question by:fskilnik
  • 10
  • 8
18 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33565835
Can you post the link to this plugin? there are many plugins called countdown

Is it this one http://keith-wood.name/countdown.html ?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33565864
0
 

Author Comment

by:fskilnik
ID: 33565923
Thanks for the quick reply, mplungjan!

Yes, that´s the countdown plugin I´m using!

I saw the "serverSync" item/function, but I do not understand php... I´m used to ASP only... could you please "translate" that to asp, for me to try?

By the way... the fact that I calculated time start + 40min = time-limit through SQLserver shouldn´t garantee that the user will have 40min to do the test in any "local" condition?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33566048
Actually no.

So there is no need for the server date.

I thought you really meant 40 minuted from server date using server date.

Just give it 40 minutes and the script should handle local time just fine

 until: new Date(new Date().getTime()+(40*60*1000))

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33566053
or
var in40Minutes = new Date();
in40Minutes.setMinutes(in40Minutes.getMinutes()+40)
.
..
until: in40Minutes
0
 

Author Comment

by:fskilnik
ID: 33566057
But using your idea, when the user "refreshes" the page (this is needed to see the next question) or changes his computer clock, the countdown time would be restarted or could be (maliciously) altered, couldn´t it?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33566094
Yes. If that is your objective, then we do need something more to stop incidental restart, but we can do nothing about malicious restart unless you calculate some kind of hash on the server that contains the start time and then when you receive the answer you compare the end time

So I suggest you create a hidden field with the hashed start time. Give the user 40 minutes local time and when the form submits, you can read the end time from the server when it hits it, and calculate from the hash if it is within a reasonable offset from 40 minutes later
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33566117
0
 

Author Comment

by:fskilnik
ID: 33566137
Nice... really nice and feasible, because I ALREADY store on my database the exact time the user clicks each answer... but let me ask you something, mplungjian... there is no way to be able to "link" the jquery countdown "strictly" to the server´s time?   I mean, the fact that the program is running in the user´s computer will ALWAYS "disturb" the until countdown parameter?    

I ask you that because from the time, saved on the server, that the user starts the test plus the 40minutes increased in the server, I have the time-limit saved on the server, so couldn´t the countdown simply be "linked" to the server and then be "immune" to local computer configurations?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:fskilnik
ID: 33566193
This EE-post seems to be able to deal with the local x server time conditions...

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23092883.html?sfQueryTermInfo=1+10+30+asp+count+down#a20689674

Do you think I could solve my problem with proper modifications?
0
 

Author Comment

by:fskilnik
ID: 33566210
The solution to the post I mentioned is YOURS, by the way!!!!
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 33566240
the countdown plugin takes a time in the future based on the current time for the user who looks at the page.

So when you are on your server, you want to know when you sent the question
When the user returns 40 minutes later, you do not care on the server, what time it was on the client, as long as it is 40 minutes later.
If you store the timestamp, you also can read the timestamp after the user submits and sends the result to your server.
The user does not care what time it is on your server then and you do not care what time it was on the client.

Yes I know :) I have answered close to 9000 questions at EE, mostly JS/HTML based
0
 

Author Comment

by:fskilnik
ID: 33566286
I got the picture, FINALLY LoL !!   I will implement your suggestion and it´s fair to consider the problem solved.

Thanks a LOT, mplungjan. Hope to see you in my next difficulties!!  :)

Best Regards,
fskilnik.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33566309
You are welcome
PS: I am not Armenian ;)
0
 

Author Comment

by:fskilnik
ID: 33567773
Thank you!   :)

P.S.: why did you say so? (I have nothing against any religion, race, culture, etc...)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33567825
I had to remove the i from mplungjian twice :)
0
 

Author Comment

by:fskilnik
ID: 33567864
Ops... I am really sorry!!!!!!    :)

Well... Feel free to mispell my surname: skilnik  (Jewish) in other opportunities...   ;)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33568064
:) no problem.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now