Counter in PHP

Asked

Viewed 1,573 times

0

I would like to be making a contactor in PHP in which I may be setting a time to be appearing the next number. For example, the number 1 appears and then the number 2 replaces the number 1. It would be in the kind of a chronometer.

They know to inform me some function that makes this substitution of numbers and another one for me to determine the time that appears the next number?

Thank you so much.

1 answer

1

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

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

Then 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>

Browser other questions tagged

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