Hi all I am really asking a more of a theoretical question here - but I am creating an application which is kind of like a true false answers webpage using PHP and have found that I now require the use of a timer. I am using MVC (codeigniter) and reload the controller when the user goes to the next question. I was wondering if you guys have any ideas of the best way to implement a timer - I can't put this on the page in JS as I assume that the timer will restart and haven't found a way of doing this in php. Is there a best practice I am missing like another controller to just perform the timer? - I apologise if this is a truly stupid question as I said its not really a coding issue yet more of a theoretical - I am also a complete beginner so please have patience
You can save the starting time in PHP and put it in a $_SESSION variable. after that give it to javascript to countdown/countup each page. even if the user manipulate your js timer, you'll know how much time has really passed in php
sample code: in your first page, where you start your quiz:
<?php session_start();
$_SESSION['startTime'] = time(); ?>
and now in other pages:
<?php session_start();
$timePassed = time() - $_SESSION['startTime']; // pass it back to javascript
?>