well,
I am using header() in middle of page sometimes
What you should do is:
Write your pages, so all HTML Output comes later, at the end of page
This way, you Will NOT Send any Header before a header() redirect.
One of these examples below would produce
Warning: headers already sent!
if was a header redirect.
Newbies often start a php page like this
<?php
echo '<html><body>'; // Any echo output will SEND HEADER!
// here comes some php script,
//and maybe header(location)
?>
Hello world!
</body></html>
while good php coders would do it like this
<?php
$html_start = '<html><body>'; // make a variable, instead of echo
// here comes some php script,
//and maybe header(location)
?>
<?php echo $html_start; ?>
Hello world!
</body></html>