报错了,有劳指教: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']);程序就执行一个打开文件的功能,功能模块是对的。
setcookie('refresh_times',++$_COOKIE['refresh_times']);这一行还是报同样的错误。Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12)
Warning:Cannot modify header information - headers already sent bu (output started at c:\123.php:12) 这很可能是文件BOM头的原因,或是你脚本不是第一行开始的。 试着换一种编辑器去掉它,或者修改 output_buffering = off 为 on
if($_COOKIE['refresh_times'] < 5){
?>
<meta http-equiv="refresh" content="10" />
<?php
setcookie('refresh_times',++$_COOKIE['refresh_times']);
}
?>或者也可以JS
<?php php程序的开始
第25行是
setcookie('refresh_times',++$_COOKIE['refresh_times']);程序就执行一个打开文件的功能,功能模块是对的。
if($_COOKIE['refresh_times'] < 5){
?>
<?php
setcookie('refresh_times',++$_COOKIE['refresh_times']);
}
<meta http-equiv="refresh" content="10" />?>
<?php
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>应该可以才对
<?php //这应该是第一行
ob_start();
?>
<更多的代码....>
<?php
更多的代码
if($_COOKIE['refresh_times'] < 5){
?>
<meta http-equiv="refresh" content="10" />
<?php
setcookie('refresh_times',++$_COOKIE['refresh_times']);
}
?>
if($_COOKIE['c'] < 5){
setcookie('c',++$_COOKIE['c']);
echo $_COOKIE['c'];
echo '<meta http-equiv="refresh" content="1" />';
}
?>
看有没错。我想是你的程序其它报的错的。
看你头部是不是输出了什么。
<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>
<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这个函数。
<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>
试着换一种编辑器去掉它,或者修改 output_buffering = off 为 on
if($_COOKIE['c'] < 5)
setcookie('c',++$_COOKIE['c']);?> 在setcookie之前已经有输出了都,请把它放在脚本最前面执行
浏览器访问/phpinfo.php,output_buffering项的值还是no value。
是不是我什么地方没改对?
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
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>