I prefer to send all of my output(including the headers) at the end of the script, after all of the processing has been done. The reason I do it that was is because if an error occurs during processing, you don't have an half loaded page, then an error. I can just scrap all of the legitiment output and display the error message.