Counter in PHP

0

I would like to be doing a PHP contactor in which I might be setting a time for the next number to appear. For example, the number 1 appears and then the number 2 appears replacing the number 1. It would be in the sort of a stopwatch.

Can you tell me a function that does this number substitution and another one to determine the time the next number appears?

Thank you in advance.

    
asked by anonymous 14.04.2018 / 01:50

1 answer

1

Well, you need to do the counter in php, something like this:

<?php 
     $num =  isset($_REQUEST["n"]) ? $_REQUEST["n"] : 0; //recebe o numero pela url
     $num++; //inclementa o numero
?>

Next comes the JavaScript part (put this at the end of the php file):

<script>
    setTimeout(function(){ //faz um teporizador
       location.href = location.href + "?n=<?=$num?>"; //atualiza a página com o $num novo
   }, 1000); //1000 milisegundos, ou seja 1s
</script>
    
14.04.2018 / 02:16