Forum
Warning: Cannot modify header information - headers already sent by...
Hi,
I uploaded a site recently for a client to review but two of the pages are showing the below warning:
Warning: Cannot modify header information - headers already sent by (output started at /home/danda/public_html/uat/services.php:1) in /home/danda/public_html/uat/perch/core/lib/PerchUtil.class.php on line 1168
Warning: Cannot modify header information - headers already sent by (output started at /home/danda/public_html/uat/services.php:1) in /home/danda/public_html/uat/perch/core/lib/PerchUtil.class.php on line 1169
Warning: Cannot modify header information - headers already sent by (output started at /home/danda/public_html/uat/services.php:1) in /home/danda/public_html/uat/perch/core/lib/PerchUtil.class.php on line 1170
Warning: Cannot modify header information - headers already sent by (output started at /home/danda/public_html/uat/services.php:1) in /home/danda/public_html/uat/perch/core/lib/PerchUtil.class.php on line 1176
I cant figure it out. I tried various solutions on Stack Overflow, but to no avail...
Does anyone know how to resolve this?
My templates aren't any different to what I would normally do..
<?php include($_SERVER["DOCUMENT_ROOT"] . '/perch/runtime.php'); ?>
<!doctype html>
<!--[if IE 8]><html class="no-js ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="no-js ie9" lang="en"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->
<?php perch_layout('global/head'); ?>
<body>
<?php perch_layout('global/header'); ?>
<main id="main-content">
<?php
perch_content_custom('Hero', array(
'template' => 'homepage_hero.html',
'page' => '/index.php'
));
perch_content('Homepage blocks');
?>
</main>
<?php
perch_layout('global/footers');
perch_page_attributes(array(
'template' => 'scripts.html'
));
?>
</body>
</html>
There is white-space somewhere which is being output before the headers are sent. Make sure there isnt any spaces before the perch runtime.
Most of the time this is a return at the top of the file befor the <?php tags
The error is pointing to line # 1 on file: services.php
If you can see any whitespace make sure the file is saved as UTF8 without a BOM.
Thanks Robert and Drew - I have encountered this before and used Notepad++ to remove the BOM. I thought I had done the same this time, but I was saving with the wrong setting under 'encoding'.
I've just started using VS Code (Visual Studio Code) as my text editor instead of Sublime Text. On the whole, I like it but it seems a couple of files were saved with BOM. Not sure if it was VS Code or me adding the BOM though, but nevermind, sorted now.
Thanks again.