Solution to the Cannotmodifyheaderinformation problem (php)

Source: Internet
Author: User
: This article describes how to solve the Cannotmodifyheaderinformation problem (php). If you are interested in the PHP Tutorial, refer to it. I have implemented a unified error prompt function. in function execution, the system first processes the error address and writes the cookie so that users can directly jump to the page to be executed after logging in, however, during the test on the server, the system prompts a local error: Warning: Cannot modify header information-headers already sent ....
Obviously, this is because of setcookie. I checked the Internet and explained the following: the cookie itself has some restrictions, for example:
1. descriptions of the call setcookie must be placed inBefore tag
2. you cannot use echo before calling setcookie.
3. the cookie will not appear in the program until the website is reinjected.
4. the setcookie function must be sent out before any information is sent to the browser.
5 .......
Based on the above restrictions, when setting the setcookie () function, we often encounter "Undefined index", "Cannot modify header information-headers already sent "... To solve the problem, the solution "Cannot modify header information-headers already sent by" is to delay the data output to the browser before the cookie is generated. therefore, you can add ob_start (); at the beginning of the program. This will solve the problem. If you want to add ob_start (), it is not feasible. it seems a little depressing that the program has been written .. when I found this error, I was wondering why I didn't prompt this problem locally. I thought it was PHP. the ini configuration is different. if you think it's wrong, it's almost the same ..
So let's look at the sentence "output started .... "It means that there is another output before setcookie, so find the file followed by output started at and check that the first line is blank. Solution complete!
Solution 2:
There are many ways to solve this problem on the Internet, but today we have encountered this problem. After the test, we found it feasible:
Find the configuration file php. ini, and then find the item: output_buffering, change its value from off to on, and restart Apache.

PS: sometimes, when you use SAE to create a php application, this can also happen if your redirection and setcookie are not supported. Follow the SAE development documentation specifications.

The above describes how to solve the Cannot modify header information problem (php), including some content, and hope to help friends who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.