Home > Backend Development > PHP Tutorial > A complete solution to the problem of Cannot modify header information in PHP_PHP Tutorial

A complete solution to the problem of Cannot modify header information in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:52:16
Original
845 people have browsed it

For such a statement, it is obvious that the reason for this is setcookie. After checking the Internet, there is the following explanation: Cookie itself has some restrictions on use, such as:
1. The description of calling setcookie must be placed in < ;html> tag before
2. Before calling setcookie, echo cannot be used
3. The cookie will not appear in the program until the web page is reloaded
4. The setcookie function must output any data to Before the browser, send
5....
Based on the above restrictions, when executing the setcookie() function, you will often encounter "Undefined index", "Cannot modify header information - headers already sent by"... The way to solve the problem of "Cannot modify header information - headers already sent by" is to delay the data output to the browser before generating the cookie. Therefore, you can add ob_start() at the front of the program; this function . This will solve it. If you want to add ob_start(), it is not feasible. It seems a bit depressing to change this after the program has been written. When I found out that this error was prompted, I was wondering why my local computer did not prompt this problem. I thought it was The PHP.ini configuration is different, but it’s wrong when I think about it. They are almost the same...
So look at the sentence "output started at...." that follows, which means that there is output in another place before setcookie , so I found the file following output started at, and saw that the first line was blank, and then Solved!
Solution 2:
The methods to solve this problem found online are mostly the same. , but I encountered such a problem again today. After trying it, I found that it works:
Find the php.ini configuration file in WINDOWS on the C drive, then search for an item: output_buffering, change its value from off to on, and restart Apache and it will be ok.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318924.htmlTechArticleSuch a statement, it is obvious that the cause of this is caused by setcookie. After checking the Internet, there is the following Explanation: Cookie itself has some restrictions on use, such as: 1. Call setcookie...
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