Search code examples
phpheaderlimit

Is there a HTTP header size limit that triggers prevent header already sent?


Maybe I am missing something, but unfortunately the above suggested link did not help me with the following problem:

I have a file (doctype_head.php) that also has an include of an authentication file for logins that I load first thing on all my webpages. Last time I logged in to check my login-system index.php file I got this warning:

Warning: Cannot modify header information - headers already sent by (output started at www.haushalts-geld.de\include\doctype_head.php:40) in www.haushalts-geld.de\login\admin\index.php on line 53

I know I get this warning because of a header() call in line 53 in index.php and I also know how to fix it. This warning seems connected to the amount of characters in "doctype_head.php". As far as I know no output is sent before the aforementioned header() call. Otherwise deleting just a few characters from my comments text (<!--bla bla-->) in "doctype_head.php" would not have solved the headers already sent warning, I guess. The thing is, everything works fine only if I keep the text in "doctype_head.php" to a certain length. I tested it up to the point where I just have to add one single character to "doctype_head.php" and get the above warning. If I remove this character again, everything works without warning.

So, that's why I wonder if it could be that I am only allowed a certain amount of characters for my HTTP header before my output starts? I thought that the included authentication file within "doctype_head.php" might be the culprit, since this alone is already about 6KB. If so, what can I do to fix this? And if not, any ideas what else I am missing? Thanks for your help.


Solution

  • So, that's why I wonder if it could be that I am only allowed a certain amount of characters for my HTTP header before my output starts?

    Not usually. Something in your application has to output something for output to begin.

    Otherwise deleting just a few characters from my comments text (<!--bla bla-->) in "doctype_head.php" would not have solved the headers already sent warning

    Your comment style is using HTML comments... not PHP comments. Anything outside of PHP open/close tags is going to be output, including HTML comments. PHP doesn't really know or care about HTML. It's just going to output it. Use PHP comments instead, inside PHP tags. (/* comment */) Better yet, never close your PHP tag. It's not necessary that you close it.