关于利用meta刷新网页的问题

tcssg0206 2011-10-17 03:55:19

我的网页想自动完成一次刷新,实现方法:

<meta http-equiv="refresh" content="10" />

尽管可以完成刷新,但是它会不停的每隔10秒就刷新一次,而我想只刷新一次或者两次。

请问该如何实现,多谢!
...全文
208 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
星星点燃我心 2011-10-18
  • 打赏
  • 举报
回复
要是在java中呢,怎么实现呢!
xuzuning 2011-10-18
  • 打赏
  • 举报
回复
<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo '<meta http-equiv="refresh" content="1" />';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html: charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
echo "刷新第 $_COOKIE[c] 次";
?>
</body>
</html>
改一下昵称 2011-10-18
  • 打赏
  • 举报
回复
<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html: charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
if($_COOKIE['c'] < 5){
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>
</body>
</html>
如果还出现Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12) 这种错误那再去改php.ini
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
我把Windows下的php.ini中的output_buffering改成=on还是不行。
浏览器访问/phpinfo.php,output_buffering项的值还是no value。
是不是我什么地方没改对?

改一下昵称 2011-10-18
  • 打赏
  • 举报
回复
没仔细看就猜测原因,这种帖子可太多了
<?php
if($_COOKIE['c'] < 5)
setcookie('c',++$_COOKIE['c']);

?>
在setcookie之前已经有输出了都,请把它放在脚本最前面执行
改一下昵称 2011-10-18
  • 打赏
  • 举报
回复
Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12) 这很可能是文件BOM头的原因,或是你脚本不是第一行开始的。
试着换一种编辑器去掉它,或者修改 output_buffering = off 为 on
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
还是不行,全部代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html: charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>
</body>
</html>
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html: charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
ob_start();
if($_COOKIE['refresh_time'] < 5){
?>
<meta http-equiv="refresh" content="1" />
<?php
setcookie('c',++$_COOKIE['c']);
}
?>
</body>
</html>

这个也是不行。

报错都是一样的,都是针对setcookie这个函数。
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
还是不行,全部代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html: charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>
</body>
</html>
ci1699 2011-10-18
  • 打赏
  • 举报
回复
你单独运行下



<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>


看有没错。我想是你的程序其它报的错的。
看你头部是不是输出了什么。
[Quote=引用 11 楼 tcssg0206 的回复:]

为什么还是报同样的错误咧?
[/Quote]
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
惭愧呀,是刚刚接触,还不敢谈及入门呀
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
为什么还是报同样的错误咧?
木目子 2011-10-18
  • 打赏
  • 举报
回复
看来楼主还真的是刚刚入门啊,我给你写的也仅仅只是一种思路而已


<?php //这应该是第一行
ob_start();
?>
<更多的代码....>
<?php
。。。更多的代码
if($_COOKIE['refresh_times'] < 5){
?>
<meta http-equiv="refresh" content="10" />
<?php
setcookie('refresh_times',++$_COOKIE['refresh_times']);
}
?>
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
还有一个疑问就是,如果用cookie,是否会影响该用户之后的访问?
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zy205817 的回复:]

利用js实现也是不错的,就是判断时间。
[/Quote]

不好意思,小弟不懂js,可否给出参考代码,我学习一下。多谢!
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
setcookie('refresh_times',++$_COOKIE['refresh_times']);

这一行还是报同样的错误。

Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12)
码无边 2011-10-18
  • 打赏
  • 举报
回复
利用js实现也是不错的,就是判断时间。
tcssg0206 2011-10-18
  • 打赏
  • 举报
回复
感谢大家!搞定了!
ci1699 2011-10-17
  • 打赏
  • 举报
回复

<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>





应该可以才对
ci1699 2011-10-17
  • 打赏
  • 举报
回复
上面错了。
加载更多回复(3)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧