Server side timer, huh?

Asked

Viewed 122 times

3

I am making a game of questions in PHP, the user will have 15 seconds to answer each question, how to prevent the user to change the timer via inspect element and add seconds?

Just adding details, it is impossible to let the user change the time from 15 to 50 seconds for example and check if the time beats via PHP because I want to implement the game so that 2 users play simultaneously, then the two of them would have 15 seconds and go through the questions together.

  • What is the language on the server? PHP or Node.js? What client-side code do you fear the user will handle? you can show the code you have?

  • 1

    Validating on the server side as well. Do not forget to give a small tolerance to compensate for the delay of the request, after all, if the user changes the timer, the time he spends for this will make a big difference. When sending the question, save the sending time on the server, when processing the answer, see if it took more than twenty seconds, for example.

  • 1

    PS: I spoke twenty as an example, in fact the ideal would be to analyze dynamically the delay of the requests and adjust accordingly, not to facilitate even for those who have a bookmarklet cheat, and not harm those who have a slow link. Or use a more "boring" protocol for this, for example, question and answer via websockets, so time would be controlled only on the server.

  • Sergio, on the server I will use PHP, I still have no code ready, before I start programming wanted to solve this problem. Bacco, but if I do, nothing prevents the player from changing the available time via element inspection.

  • What code do you have so far?

2 answers

0

Maybe you can save on the server side the time (timestamp) when the question was sent and then compare it to the time when the answer was sent.

If the difference is less than your limit (with a fatty for network latency questions), you accept the answer. Otherwise (i.e., if the difference is greater than acceptable), does not accept and returns an error.

This way the client-side counter becomes just a view, but its validation is secured on the server side.

-1

You do it off the page, you create a file just for that, and in it, you store the time information going by, so when the user switches on the clement inspect, the value that they type, regardless of which, will return to normal according to the variable in your file, and even, can make a script to check if it was changed by the user and pebble, disqualify it from your game

  • I don’t understand your idea.

  • timer = 5; // seconds $("#element"). text(timer); var interval = setInterval(Function(){ var statewide = $("#element"). text(); if( state == timer ){ timer--; $("#element"). text(timer); }Else{ //what happens if user tried to cheat console.log("Timer changed by user") clearInterval(interval); } if( timer == 0){ clearInterval(interval); fimdotempo(); } }, 1000); Function fimdotempo() { //code for end-time console.log("End-of-time"); }

  • This does not solve the problem, just change the variable timer and will have the scenario I commented.

  • Then the user will only be able to change the timer if you want 1000 to pebble, some 5000, and if he changes the count to, and there is a space for you to decide what happens if that happens

  • put it in a timer.js file and call on your page

  • Valim, anyway, the user can change, just delete the part that includes the file timer.js and modify. Javascript on the client side doesn’t seem like a solution.

  • delete the file not to the code, and no use it change on the client side, does not change the counter, if it manages to change the count to, test there and see

  • even excluding the page counter the code will not stop running, and at the end it will pass

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.