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(); ?>
- View All Symlinks in a Directory Tree on Linux
- /etc/init.d/redis-server on Debian 9.5 Stretch
- View Last Time a File was Opened on Debian
- Fix PHP7.0-FPM Installation (Sury.org Packages)
- Server Certificate Verification failed CAfile (apt-get update)
- 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
- Htaccess file for WordPress websites
- How to Create Backups of MySQL via PHP
- Transfer files from a VPS to a FTP web hosting server
- 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