Alternatively, not to think about a newline or space somewhere in the file, you can buffer the output. Basically, you call ob_start()
at the very beginning of the file and ob_end_flush()
at the end. You can find more details at php.net ob-start function description.
Edit: If you use buffering, you can output HTML before and after header() function - buffering will then ignore the output and return only the redirection header.