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):
echo "
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.