0

During testing of my website I was noticing that I was receiving this error multiple times:

Warning: Cannot modify header information - headers already sent by (output started at /home/example/public_html/file.php:100)

When I examined the error (searched here on SO), I discovered that the whitespace lines after my ?> delimiter was causing the issue.

My question is: Why does the whitespace after the PHP delimiter cause this error when there is no more code? Shouldn't the file stop reading when there is no more content and just a PHP ending delimiter ?

  • I know that whitespace after the ?> delimiter causes an error, that is not my question; thus not relating to a duplicate question.
Pat Green
  • 95
  • 1
  • 8
  • 2
    No, you can open and close as many php blocks as you want and put other things like html or javascript in between or after the last closing delimiter. – jeroen Aug 10 '15 at 11:31
  • Thank you, I have edited my question since your answer, sir. – Pat Green Aug 10 '15 at 11:34
  • Define content. A space character or new line is valid html. – jeroen Aug 10 '15 at 11:38
  • I understand now, perhaps I was thinking that whitespace would not be read as HTML. Thanks. – Pat Green Aug 10 '15 at 11:40
  • I hope you can get the detailed information from this [question](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Gunaseelan Aug 10 '15 at 11:59

2 Answers2

2

Anything other than PHP is interpreted as HTML and output to the browser, so that space after ?> is sent to the browser.

You can no longer redirect after you have sent anything to the browser, whether an explicit header, or just some HTML which will have an implicit HTTP header.

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
0

It means you are trying to change the header, but you have output data already. You can't output something and then change the header. If you search here on SO, you should've found this post: How to fix “Headers already sent” error in PHP.

It explains why you have the error and how you should fix it.