The function, "header", can not be called if you've already made the script output text to the client.
For example:
<?php
echo 'Hello World!'
header('Content-type: text/plain');
?>
Will throw an error, because it tried to modify the header after all of the headers were sent to the client.
<?php
header('Content-type: text/plain');
echo 'Hello World!'
?>
This will work. Because the header is modified, and then output is sent.