PHP Cannot modify header information

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/test.php:3) in /home/user/public_html/test.php on line 4


Look familiar? This PHP error has haunted website owners for years. Please understand, ABACOHosting does not normally support your webdesign and coding, but this error is too common for us to ignore. So, one of our PHP experts has the answer for you.

The problem you face is that you are trying to use the PHP header function, header(), but there can be absolutely no HTML output before this function is declared. Let's use some examples:

<!DOCTYPE "HTML 4.01 Transitional EN" "http://www.w3.org/">
<html><body>
<?php header ('Location: http://abacohosting.com/'); ?>
</body>
</html>


This is incorrect coding. You cannot have any HTML preceding the header function. A few more bad examples:

<?php
echo "Task complete.";
header ('Location: http://abacohosting.com');
?>
Task complete! <?php
header ('Location: http://abacohosting.com');
?>


This is incorrect coding for the same reason. You cannot have any text output before the header function. Plain text is always treated as HTML by your browser. One more bad example:

 <?php
header ('Location: http://abacohosting.com');
?>


This one is tricky. The blank space before the PHP tag counts as HTML output.

It is acceptable to have other PHP code before the header function, as long as nothing is outputted as HTML. This is a correct example:

<?php
$variable = "value";
mysql_query("blah blah");
header ('Location: http://abacohosting.com');
?>


I hope this helps. Remember, our technicians cannot fix your PHP code, so if you need more help, please refer to http://us.php.net/manual/en/index.php
  • PHP
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Ports open for outgoing connections

Abaco Hosting has opened the following ports for outgoing connections on its Hosting Servers:...

How do I access cPanel?

1. Managing your Linux Hosting package through your web browsercPanel can be accessed by using...

Uploading Content to your cPanel Linux Hosting Package

To upload content to your Hosting package through an FTP client, use only FTPS on Port 21.Some...

SymLinks Settings of cPanel Linux Hosting packages

Linux Hosting packages do not support the "FollowSymlinks" option in the .htaccess file. This...

Directory and File Structure - Linux

Directory/Folder StructureFrom amongst the several directories found within your cPanel account,...

Powered by WHMCompleteSolution