php Cannot modify header informationheaders already sent by解_PHP教程

WBOY
Release: 2016-07-13 10:57:03
Original
836 people have browsed it

If you see this warning when executing a php program: "Warning: Cannot modify header information - headers already sent by ...."

Few notes based on the following user posts:
There are several solutions:

1. Blank lines:
Make sure no blank line after of the calling php scrīpt.
Check that there are no blank lines after , especially include or require files. Many problems are caused by these blank lines.

2. Use exit statement (use exit to solve):
Use exit after header statement seems to help some people
Add exit();
after the header header ("Location: xxx");
exit();

3a. Use Javascrīpt (use Javascrīpt to solve):
self.location( file.php );"; ?>
Since it s a scrīpt, it won't modify the header until execution of Javascrīpt.
Javascript can be used instead of header. Also note that using this method requires the browser to support Javascrīpt.

3b. Use output buffering (use output buffering to solve):

... HTML codes ...
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>

Another article

ob_start();
setcookie("username","Song Yanbin",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 Cause of error
I added it at the head of the php program,

header("cache-control:no-cache,must-revalidate");

After that, the above error appeared on the page, and even after reading N information, there was no result. Today I accidentally discovered that there was something wrong with the configuration in my php.ini. I found the php.ini file under C:windows
output_buffering defaults to off.

Tips, a better solution is to set output_buffering to on [...] in php.ini and this kind of problem will not occur.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632112.htmlTechArticleIf you see this warning when executing the php program: Warning: Cannot modify header information - headers already sent by . ... Few notes based on the following user posts: There are several solutions...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template