How to solve the Cannotmodifyheaderinformation problem in php _ PHP Tutorial

Source: Internet
Author: User
Php provides a complete solution to the Cannotmodifyheaderinformation problem. Obviously, this is because of setcookie. I checked the Internet and explained the following: the cookie itself has some restrictions, for example: 1. the reason for calling the setcookie statement is obviously due to the 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 in WINDOWS on drive C, and then find the item: output_buffering, change its value from the original off to on, and restart Apache.

Response 1. call setcookie...

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.