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

时间:2018-04-28 19:01:18

标签: php

My Boss给我一个项目,我必须在PHP中显示每30分钟的实时倒计时,任何人都可以帮我怎么做?对不起我的坏英语

1 个答案:

答案 0 :(得分:1)

您可以通过简单的方式完成此操作。我已经做过了。

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