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(); ?>
- Send Transactional Email with SendGrid in PHP
- Send Email with PHPMailer using SMTP
- Fortnite TCP/UDP Ports to Open on Router or Firewall
- jQuery simple alert message that fades out after N seconds
- Edit /etc/hosts on Mac OSX
- Set $_SERVER['REQUEST_URI'] when running PHP script from terminal
- View All Available Code Sign Certificates on USB Token
- Close program with ESC key in Delphi
- VMware USB Arbitration Service Error 2: The system cannot find the file specified
- PDFYeah: Online Cloud-Based PDF Converter
- Create a SOCKS 5 Proxy on Top of a SSH Tunnel on Linux
- Estimate Number of Visitors and Pageviews of any Website
- Integrate Disqus on WordPress programmatically
- Disable Compression when Encrypting with GNU GPG
- ERROR 1932 (42S02): Table doesn't exist in engine
- Minify & Compress CSS with online tools