php Cannot modify header informationheaders already sent by解_PHP教程
Few notes based on the following user posts:
有以下几种解决方法:
1. Blank lines (空白行):
Make sure no blank line after of the calling php scrīpt.
检查有 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。
2. Use exit statement (用exit来解决):
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit();
3a. Use Javascrīpt (用Javascrīpt来解决):
echo "
Since it s a scrīpt, it won t modify the header until execution of Javascrīpt.
可以用Javascrīpt来代替header。另外需要注意,采用这种方法需要浏览器支持Javascrīpt.
3b. Use output buffering (用输出缓存来解决):
... HTML codes ...
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>
另一篇文章
ob_start();
setcookie("username","宋岩宾",time()+3600);
echo "the username is:".$HTTP_COOKIE_VARS["username"]."n";
echo "the username is:".$_COOKIE["username"]."n";
print_r($_COOKIE);
?>
Warning: Cannot modify header information - headers already sent by出错的原因
我在php程序的头部加了,
header("cache-control:no-cache,must-revalidate");
之后页面就出现上面的错误,看了N个资料也没有结果。今天偶尔发现原来是我的php.ini里面的配置出了问题,在C:windows下找到php.ini文件
output_buffering默认为off的。
小提示,还有一个更好的解决办法就是在php.ini 然后把 output_buffering 设为 on [...]就不会出现这类问题了。
上一篇: 身份证号码校验
下一篇: php 正则表达式捕获组与非捕获组
推荐阅读
-
php 报错 Cannot modify header information,modifyheader_PHP教程
-
Cannot modify header information - headers already sent by出错_PHP教程
-
php Cannot modify header information-headers already sent by解决办法
-
完美解决PHP中的Cannot modify header information 问题_PHP教程
-
Cannot modify header information错误解决方法_PHP教程
-
PHP提示Cannot modify header information - headers already sent by解决方法
-
PHP错误Warning: Cannot modify header information - headers already sent by解决方法
-
setcookie中Cannot modify header information-headers already_PHP
-
php Cannot send session cookie-headers already sent by的解决方法_PHP教程
-
php中出现Cannot modify header information的解决办法_PHP教程