
Dave
Staff
/ Moderator

Aug 17, 2011, 2:53 PM
Post #6 of 9
(1196 views)
Shortcut
|
|
Re: [ITI] headers_sent() issue with plugins and instant website
[In reply to]
|
Can't Post
|
|
Hi Glen, If you send headers after you've sent content you'll get a warning from PHP regardless, so the idea with the die call is it shows just that one error and nothing else so it's more noticable instead of PHPs default warning somewhere in the page content, which looks like this: "Warning: Cannot modify header information - headers already sent by ...". The problem with removing that line (or sending content before headers such as with whitespace in plugins) is that if header have already been sent (which means page content or whitespace has been sent) no more HTTP headers can be sent (and you can't set cookies or, session values either). So, for example, this would produce a "headers already sent" error:
print " "; ob_flush(); header("HTTP/1.0 404 Not Found"); print "<h1>404 Not Found</h1>"; print "done"; I'm thinking it may be a server-side caching issue. That IIS sometimes hasn't yet sent the content to PHP so PHP doesn't know headers have been sent. Can you try adding this line and let me know if you get the error all the time?
ob_flush(); if (headers_sent($file, $line)) { die("You must load " .basename(__FILE__). " at top of file! Make sure there are no extra spaces before it (or at the end of any plugins)! Output started in $file line $line.\n"); } Anyways, with Instant Website I don't think it's matters much and it's pretty safe to remove that line. All it does is prevent you from getting a different error when the 404 code is called. So if it's not proving helpful removing it is probably the way to go. Also, it gives me an idea that maybe we could auto-detect the whitespace at the end of plugins in CMSB init and warn developers about it. Let me know if ob_flush() gives you different results (and if you have any extensions that automatically gzencode/compress output or anything like that. Thanks! Dave Edis - Senior Developer interactivetools.com
|