mardi 10 mars 2020

How do i constantly check a if statement in php?

I have a php if statement to check server time, if is certain hour it runs a jquery function.

problem is it only gets fired once when page loads. i know how to it with javascript, but i need the if statement to be php cause i need to check the server time, not current time of user browser.

something like check it every 10sec would be ideal i guess

the code in the footer.php:

<?php
date_default_timezone_set('Europe/Rome'); // CET
$info = getdate();
$hour = $info['hours'];
if ($hour >= 8 && $hour <= 22){ ?>
    <script type="text/javascript">
    jQuery(document).ready(function(){
            document.getElementById("myid").innerHTML = "OPEN";
            document.getElementById("myid").setAttribute("class", "open");
    });
    </script>
<?php }else{ ?>
    <script type="text/javascript">
    jQuery(document).ready(function(){
            document.getElementById("myid").innerHTML = "CLOSED";
            document.getElementById("myid").setAttribute("class", "closed");
    });
    </script>
<?php } ?>

Aucun commentaire:

Enregistrer un commentaire