我的网页想自动完成一次刷新,实现方法:<meta http-equiv="refresh" content="10" />尽管可以完成刷新,但是它会不停的每隔10秒就刷新一次,而我想只刷新一次或者两次。请问该如何实现,多谢!

解决方案 »

  1.   

    PHP可以这样:<?php
    if($_COOKIE['refresh_times'] < 5){
    ?>
    <meta http-equiv="refresh" content="10" />
    <?php
    setcookie('refresh_times',++$_COOKIE['refresh_times']);
    }
    ?>或者也可以JS
      

  2.   

    报错了,有劳指教:Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12) in c:\123.php on line 25其中第12行是
    <?php  php程序的开始
    第25行是
    setcookie('refresh_times',++$_COOKIE['refresh_times']);程序就执行一个打开文件的功能,功能模块是对的。
      

  3.   

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

  4.   


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

  5.   

    setcookie('refresh_times',++$_COOKIE['refresh_times']);这一行还是报同样的错误。Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12) 
      

  6.   

    还有一个疑问就是,如果用cookie,是否会影响该用户之后的访问?
      

  7.   

    看来楼主还真的是刚刚入门啊,我给你写的也仅仅只是一种思路而已
    <?php //这应该是第一行
    ob_start();
    ?>
    <更多的代码....>
    <?php
    更多的代码
    if($_COOKIE['refresh_times'] < 5){
    ?>
    <meta http-equiv="refresh" content="10" />
    <?php
    setcookie('refresh_times',++$_COOKIE['refresh_times']);
    }
    ?>
      

  8.   

    你单独运行下<?php
    if($_COOKIE['c'] < 5){
    setcookie('c',++$_COOKIE['c']);
    echo $_COOKIE['c'];
    echo '<meta http-equiv="refresh" content="1" />';
    }
    ?>
    看有没错。我想是你的程序其它报的错的。
    看你头部是不是输出了什么。
      

  9.   

    还是不行,全部代码如下:<!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>
      

  10.   

    <!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这个函数。
      

  11.   

    还是不行,全部代码如下:<!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>
      

  12.   

    Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12)  这很可能是文件BOM头的原因,或是你脚本不是第一行开始的。 
    试着换一种编辑器去掉它,或者修改 output_buffering = off 为 on 
      

  13.   

    没仔细看就猜测原因,这种帖子可太多了<?php
    if($_COOKIE['c'] < 5)
    setcookie('c',++$_COOKIE['c']);?> 在setcookie之前已经有输出了都,请把它放在脚本最前面执行
      

  14.   

    我把Windows下的php.ini中的output_buffering改成=on还是不行。
    浏览器访问/phpinfo.php,output_buffering项的值还是no value。
    是不是我什么地方没改对?
      

  15.   

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

  16.   

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

  17.   

    要是在java中呢,怎么实现呢!