PHP timer for a javascript function


I have asetInterval timer and it stores its information into database. Somehow people manage to cheat me. What I need is a PHP function to calculate time since Javascript timer has started and save time in DB? Is that even possible?




I think you call your PHP script using an Ajax call from setInterval. So you can use in you're ajax complete callback :

var end = new Date().getTime();
var time = end - start; // start is defined before ajax call
console.log('Execution time: ' + time);

If you need to calculate it form server-side, use time() in PHP

People are also looking for solutions to the problem: php - Format Form Validation Message in Laravel 5


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.