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(); ?>
- Block Paltalk Ads (and Others) via Hosts file
- E: Sub-process /usr/bin/dpkg returned an error code (2)
- How to Validate JSON in PHP
- The program can’t start because VCRUNTIME140.DLL is missing
- PHP CURL Download Remote URL to File
- PHP Check if a file was modified more than 1 hour ago
- Linux -bash: Input/output error or -bash: Read-only file system
- Dropzone.js: Drag’n’Drop File Uploads with Image Previews
- Lost connection during Debian apt-get upgrade
- Bootstrap 3 Navbar with Logo Image
- Redis HMGET, HGETALL, HSET, HGET Benchmark
- PHP GetHostByName() Slow? Make it Faster
- Use Timestamp with new DateTime() in PHP
- Calculate Elapsed Time Between Two Dates in PHP
- PHP Display Date Same as Server HTTP Headers Date
- PHP cURL Download Size Limit