In the valid everything being outputted to the browser is outputted after the header declaration. In the invalids things are being outputted before the header declaration. If you provide your full code we can be more specific, you can censor out secure parts with '****'.

