I don't know why your first example doesn't kick the same error.
It should. From the
documentation [us2.php.net]: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
What this is telling you, from your original example,
<html>
just a few lines of info
The previous is
output. So issuing a header
after "<html>just a few lines" is going to kick this error, because it has automatically issued a content-type:text/html header merely by the presence of "some content" before the header.
Note that this is not really a PHP issue, PHP just confuses the issue. When you request a document, you can send any number of headers, several of them, if you want. But those all must come
first before document output. Once the document begins output, you can't send another header. That's just the way it is. :-) If you did this in any other language,
print "content-type:text/html\n\n"; # content-type header
print '<p>Here is some output</p>';
print "content-type:text/html";
You would get the header as
content. <p>Here is some output</p>
content-type:text/html
The example from the link above is pretty explicit,
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
?>
If you need to do something before issuing header(), wrap it all in PHP and don't
output anything until it's ready.
include("some-file-with-functions.php");
$errors = cleanse_data();
if ($errors) { header("location:/try-again.php"); }
<!-- the previous will EXIT -->
<html>
<head><title>Blah</title></head>
.....