PHP Warning: Cannot modify header information
PHP Warning: Cannot modify header information – headers already sent in …
Sometimes you might see this message in the server error log or have it displayed on a web page. It’s frustrating and looks like something’s wrong with the PHP script that is mentioned in the message. In fact, this message indicates a problem (a bug) in another script, plugin or a theme. You can get this message if you use a buggy plugin and displaying PHP errors is turned on, which normally should not be.
This message appears when some piece of PHP code on a website generates an output, which typically is a PHP warning message that should not be sent and shown in the users’ browser at all. And this output is sent before a header of the web page is generated and sent to a user browser. The header of a webpage can be empty or can handle additional information such as cookies.
Whether the header is empty or not, it must be sent before any page content.
If a buggy WordPress plugin generates a PHP warning before other plugins send headers to a browser, it leads to a server error with the message “PHP Warning: Cannot modify header information – headers already sent in …” .
Such a message can mislead anyone because it doesn’t tell what script or a plugin caused this error. When a web server detects any output generated by a plugin with no header sent, it creates the header automatically and sends it to the browsers, so all other plugins which don’t expect such behavior, are unable to send their headers if they need to.
How to solve this issue in the context of using WP Cerber Security
- Disable error displaying in the PHP settings of your hosting control panel. If you don’t have access to PHP settings, ask your hosting provider for assistance.
- Disable PHP error displaying in the WP Cerber settings on the Hardening admin page.
- In the Main Settings of WP Cerber, set “Load security engine” to “Standard mode” or “Advanced mode”.
- Check if the WP_DEBUG constant is defined in the wp-config.php file. Comment out the line with double slashes // or just delete the whole line. This is how it should look:
// define( 'WP_DEBUG', true );
// define( 'WP_DEBUG', 1 );
- Add the following lines to the beginning of the wp-config.php file:
@ini_set( 'display_errors', 0 );
@ini_set( 'log_errors', 1 );
Can WP Cerber or WordPress be the cause of the issue?
No. The only code that can cause this issue is either an outdated/buggy plugin or the active theme. How to find the root cause? Check the server error log. And please get rid of outdated plugins.
Have any questions?
If you have a question regarding WordPress security or WP Cerber, leave them in the comment section below or get them answered here: G2.COM/WPCerber.