Posted on June 17, 2018 at 12:09 pm
Here you will find various solutions to fix this PHP error message:
Cannot modify header information - headers already sent
Solution 1 – UTF-8 without BOM
Make sure the file encoding format of all PHP files is UTF-8 without BOM.
You can use Notepad++ to convert the encoding format of your PHP files.
Solution 2 – Remove blank lines before/after PHP tags
Make sure there are no blank lines sent before the HTML tag:
To fix those blank lines, check all PHP files included/required before showing the page header.
Then make sure there are no spaces or blank lines before <?php and at end of ?>
Each PHP file should start with <?php and end with ?>.
No blank lines should be present before or after those tags, else they are sent to the client.
And thus you would not be able to modify the headers because they’re already set.
Solution 3 – Use CSS files, not <style>…</style>
Inside the HEAD tag, make sure to load the CSS code from .css files.
Do not write it within <style>…</style> tags, else it seems to cause “headers” issues.
In my case, I had to use .css files to fix the “Cannot modify headers” issue.
Solution 4 – Try using ob_start();
Add ob_start(); at the very top of your PHP script.
Then add ob_end_flush(); at the very end of your PHP script.
This would most probably fix any “Cannot modify headers” issues.
Here is an example usage:
<?php ob_start(); ?> <html> <!-- Output --> </html> <?php ob_end_flush(); ?>
- Restarting nginx: [emerg]: directive "rewrite" is not terminated by ";"
- Programmatically Lookup File Hash on VirusTotal
- Compress MP4 videos online for free
- Stop ad blocking on your website
- Windows 10 Edition Upgrade Via ChangePk.exe and DISM
- Open Windows Explorer with a specific file selected
- Download Adobe Creative Suite 6 Applications (Windows\Mac)
- Force Apt-get to use IPv4 on Debian Linux
- Sandboxie SBIE2205 "Service not Available: CreateDesktop" Firefox
- Cannot modify header information - headers already sent
- Install MariaDB 10.3 Server on Debian Linux
- Install Only MariaDB Client on Debian Linux
- Install only MySQL Client on Debian Linux
- Send Transactional Email with SendGrid in PHP
- Send Email with PHPMailer using SMTP