当前位置: 代码迷 >> PHP >> php自动刷新页面,该如何处理
  详细解决方案

php自动刷新页面,该如何处理

热度:75   发布时间:2016-04-28 17:16:32.0
php自动刷新页面
PHP中怎么样自动刷新当前页面,5秒钟刷新一次,刷新10次停止刷新,给个代码。看了JS刷新,只能设置定时刷新和多少时间刷新一次,不能实现刷新多少次停止。
------解决思路----------------------

<?
ob_start();
if(!isset($_COOKIE['times'])){
    $times = 0;
    setcookie('times',$times,time()+3600);
}else{
    $times = $_COOKIE['times']+1;
    if($times<=10){
        setcookie('times',$times,time()+3600);
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>每5秒刷新1次,共刷新10次</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <?php if($times<10){ ?>
  <meta http-equiv="refresh" content="5" />
  <?php } ?>
 </head>

 <body>
  <p>每5秒刷新一次,共刷新10次,当前已刷新<?php echo $times ?>次</p>
 </body>
</html>
  相关解决方案