php Cannot modify header information - headers already sent_PHP教程

WBOY
Release: 2016-07-13 10:55:43
Original
827 people have browsed it

This article introduces various solutions to php Cannot modify header information - headers already sent by set , friends who need it can refer to it.

Set output_buffering to On in the php configuration file php.ini. Just turn it on.

output_buffering = On 

----------------------------------
All or nothing, now or never.


There are several solutions:

1. Blank lines:
Make sure no blank line after of the calling php script.
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):

The code is as follows
 代码如下 复制代码
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit();
Copy code

Use exit after header statement seems to help some people
 代码如下 复制代码

Add exit();

after the header header ("Location: xxx");
exit();

 代码如下 复制代码

... HTML codes ...
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>
Use Javascript (use Javascript to solve):
The code is as follows
Copy code

Since it's a script, it won't modify the header until execution of Javascript. You can use Javascript to replace the header. But I did not execute the above code successfully... Also note that using this method requires the browser to support Javascript. 3b. Use output buffering (use output buffering to solve):
The code is as follows Copy code
... HTML codes ... ... PHP codes ...

header ("Location: ...."); ob_end_flush();
?> http://www.bkjia.com/PHPjc/632237.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632237.htmlTechArticleThis article introduces a variety of solutions to php Cannot modify header information - headers already sent by set, if necessary Friends can refer to it. In the php configuration file php.ini...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!