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>