0

Why is white space an issue in the first piece of code (particularly in regards to output buffering) but not an issue in the second piece of code:

May cause issues:

echo "</body>";
echo "</html>";
?>
//white space here

Does not cause issues:

?>
</body>
</html>
//white space here

The reason I'm asking is that it is perfectly valid to have white space at the end of HTML code and both code examples will place the white space after the closing </html> tag.

Please do not say this is a duplicate of another page unless the other page gives a reason as to why the second example does not cause issues.

kojow7
  • 10,308
  • 17
  • 80
  • 135
  • 1
    Are either a security risk? – andrewsi Oct 28 '15 at 17:38
  • Do you have a link of any kind where they claim that this represents a *security* risk? – Álvaro González Oct 28 '15 at 17:38
  • Where did you get this info that it can be considered a security risk? Any links to articles? – jpaljasma Oct 28 '15 at 17:39
  • 4
    http://stackoverflow.com/questions/4410704/why-would-one-omit-the-close-tag – ka_lin Oct 28 '15 at 17:39
  • Please share some source where it says that the first code snippet has a "security risk" – taxicala Oct 28 '15 at 17:45
  • I would call @KA_lin's link a duplicate, *n'est-ce-pas true?* - After what I read anyway. – Funk Forty Niner Oct 28 '15 at 17:55
  • *"Please do not say this is a duplicate of another page unless the other page does indeed say why the second example is not a security risk."* - So, what say ye? That link left above; does or doesn't constitute as a duplicate? – Funk Forty Niner Oct 28 '15 at 18:04
  • I have changed my question to remove "security risk" from it. Also, I have previously read over a number of pages (including the one linked as a supposed duplicate). They do not answer my question as to why whitespace in the second example is fine whereas whitespace in the first example is not. In my opinion they seem to do exactly the same thing. – kojow7 Oct 28 '15 at 18:34
  • 1
    The whitespace in your examples would not typically be problematic as both are echoing at the same time in the request/response cycle. The most common reason to be wary of whitespace at the end of files is the [headers already sent](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) error beginners often encounter. – ceejayoz Oct 28 '15 at 18:39
  • 1
    Neither of your examples would cause any issues, as far as I can see. I think you maybe misinterpreted some advice you were given, or maybe it was bad advice. – Boann Oct 28 '15 at 21:06
  • @ceejayoz thanks, you have answered my question! Would the "headers already sent" issue typically only come in to play when including one php file inside another? – kojow7 Oct 28 '15 at 22:58

0 Answers0