Thursday, October 9, 2014

HTTP Header already sent

This will happen if you include a separate php form on the index.php page, but you have something else (other html code) before this php form. In this case, you need to turn on output buffering.

There are some Lynda.com videos which offer detailed explanation on HTTP header and output buffering:

PHP with MySQL Essential Training - Modifying Headers, page redirection, and output buffering

You can turn on output buffering either on each php file, or you can do it in the php.ini. Only one way is required but you are free to do both. 

Very often, you won't have access to your php.ini files on the server. You can modify all php files by doing the below:

at the beginning of all the php files, write
  ob_start(); 
?> 

at the very end of the php files, write
  ob_end_flush(); 
?> 

Bear in mind that if you do an include (anotherfile.php) in the index.php file, you might need to modify the file directories for the css, js, or whatever other files you have in the included php file, as this file is seeing the folder structure from the root level. 

No comments:

Post a Comment