首页 > 解决方案 > PHP每30分钟实时倒计时

问题描述

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

标签: php

解决方案


您可以通过简单的方式做到这一点。我已经做到了。

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

推荐阅读