Solve warning: cannot modify header information-headers already sent B...

Source: Internet
Author: User
Tags wordpress blog

SolutionWarning: Require (E: \ testwwwroot \ cc06 \ WP-admin/WP-includes/compat. php) [function. Require]: failed to open stream: no such file or directory inE: \ testwwwroot \ cc06 \ WP-admin \ wp-settings.phpOn Line246
Fatal Error: Require () [function. require]: Failed opening required' E: \ testwwwroot \ cc06 \ WP-admin/WP-nodes des/compat. PHP '(include_path = '.; c: \ PhP5 \ pear ') inE: \ testwwwroot \ cc06 \ WP-admin \ wp-settings.phpOn Line246.

1. blank lines (blank line): Make sure no blank line after <? PHP...?> Of the calling PHP script. Check for <? PHP...?> There are no blank lines, especially include or require files. Many problems are caused by these blank rows.



2. use Exit Statement (solved by exit): Use Exit after header statement seems to help some people add exit (); header ("Location: XXX") after the header "); exit ();


3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it'll said "Warning: cannot modify header information-headers already sent .... "Basically anytime you output to browser, the header is set and cannot be modified. so two ways to get around the problem:

3A. use JavaScript (solved using JavaScript): <? Echo "<SCRIPT> self. Location (\" file. php \ "); </SCRIPT>";?> Since it's a script, it won't modify the header until execution of JavaScript. You can use JavaScript to replace the header. However, the above Code is not successfully executed... You need to note that using this method requires the browser to support JavaScript.

3B. Use output buffering (solved by the output cache): <? PHP ob_start ();?> ... Html codes... <? PHP... PHP codes... header ("Location:..."); ob_end_flush ();?> This will save the output buffer on server and not output to browser yet, which means you can modify the header all you want until the ob_end_flush () statement. this method is cleaner than the Javascript since JavaScript method assumes the browser has JavaScript turn on. however, there are overhead to store output buffer on server before output, but with modern hardware I wocould imagine it won't be that big of deal. javascript solution wocould be better if you know for sure your user has JavaScript turn on their browser.

As in the code above, this method is cached when the page is generated, so that the header can be output after the head is output. This method is used to solve the header problem.

Http:// Tid = 70318

In the background management or sometimes in the Forum, click a page, the top of the page will show warning: cannot modify header information-headers already sent .... this is because of the setcookie statement.
There are some restrictions on the use of cookies, such as: 1. the description of the call to setcookie must be placed before the <HTML> mark 2. you cannot use echo 3 before calling setcookie. the cookie does not appear in the program until the website is reinjected. the setcookie function must be sent 5 before any information is sent to the receiver. ...... Based on the above restrictions, when setting the setcookie () function, we often encounter "undefined Index", "cannot modify header information-headers already sent "... To solve this problem, the method of "cannot modify header information-headers already sent by" is before the cookie is generated, extend the token to the receiver. Therefore, you can add ob_start (); at the beginning of the program. This will solve the problem.


4. set output_buffering = on in PHP. INI (enable PHP. output_buffering in ini) set output_buffering = on will enable output buffering for all files. but this method may slow down your PHP output. the performance of this method depends on which web server you're working with, and what kind of scripts you're using. this method is the same as 3B in theory. However, This method enables the output cache of all PHP programs, which may affect the PHP Execution efficiency, depending on the server performance and Code complexity.



When a WordPress program is executed, it first calls a configuration file such as the wp-config.php, and also calls the wp-db.php to establish a database connection for later use. These files only make some settings and do not output HTML code. After the settings are complete, the program itself starts to execute. Some programs will use the header command to set an HTTP header. Because the HTTP header must be set before HTML code output, otherwise the HTML code has already been sent to the client, and HTTP has already been sent and cannot be recovered. WordPress Codex explained this problem: how do I solveHeaders already sentWarning Problem?. The article states that it is necessary to ensure that each file, especially the frequently edited wp-config.php file<?phpStarting?>It cannot end with any other character. Specifically to the above example, it is obvious that the prompt information says the first line of the wp-config.php begins the HTML output, which may be the first line<?phpOther characters added to the front, such as spaces. Again think of the previously mentioned BOM problem, it is very likely that this friend used Windows notepad to edit the wp-config.php file and save it as a UTF-8 encoded document, therefore, an error occurred while executing the header command because the BOM output contains three characters.

The WordPress Chinese forum does not provide the full-text search function, so I can only search for titles. So I used Google to search for cannot modify header information site: It seems that many people have encountered this problem. At present, WordPress is mainly used in the original WordPress English version and several WordPress Chinese versions. My Chinese package does not contain wp-config-sample.php files, naturally none of my business; the original WordPress ASCII code, naturally does not contain Bom, will not make such an error; the Chinese version of WordPress made by Xigang is available in the WordPress Chinese forum. I downloaded WordPress 2.0.4 and 2.0.3 and checked them. There is no problem. In the Chinese version of WordPress 2.0.4, the wp-config-sample.php file uses gb2312 encoding and DOS line tail, God! However, if someone uses notepad to modify the file, the DOS line tail will not cause editing problems, and gb2312 encoding will not cause BOM problems.

Alas, if you want to use the Wordpress blog, you should discard the notepad and install ultraedit or editplus!

Update:Those prompts (output started at \ WP-warning des \ wp-db.php: 104), I opened the wp-db.php file and looked at it, 104 rows seem to be wrong with the output database. Check your database connection. Is there any problem on IIS?

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: 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.