PHP 每 30 分钟实时倒计时一次



我的老板给我一个项目,在这个项目中,我必须在PHP中显示每30分钟的实时倒计时,任何人都可以帮助我如何做到这一点? 对不起我的英语不好

您可以通过简单的方式执行此操作。我已经做到了。

<?php
    $time_on =1800;
    header( "refresh:$time_on; url=https://localhost/your_project/your_file.php");
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style type="text/css">
        .myClass {
            font-family: verdana; 
            font-size: 16px; 
            font-weight: normal;  
            color: black;
            line-height: 30px;
        }
   </style>
 </head>
 <body>
     <script type="text/javascript">
        (function () {
            var timeLeft = <?php echo $time_on; ?>,
            cinterval;
            var timeDec = function (){
                timeLeft--;
                document.getElementById('countdown').innerHTML = timeLeft;
                if(timeLeft === 0){
                    clearInterval(cinterval);
                }
            };
            cinterval = setInterval(timeDec, 1000);
         })();
      </script>
      Redirecting in <span id="countdown"><?php echo floor($time_on); ?></span> seconds.<br><br>
      <span class="myClass">Time Start</span>
    </body>
</html>

最新更新