Jim,
I have done exactly the same thing you described below, by adding
debugging code, forgetting to find/remove all of it, and then running
into "headers already sent" issues. On the proposal page below, in a
comment, I proposed a variation that solves this type of problem, and
even allows such debugging comments to remain in production ZF code
(not everywhere, but most places) without causing problems.
http://framework.zend.com/wiki/display/ZFPROP/Zend_Controller_Response+output+buffering
Cheers,
Gavin
P.S. I am cross-posting since this use case appears relevant to the
Controller proposal above.
Jim Scherer wrote:
Gavin,
Thank you. I know understand what was happening on my production machine.
Why "some sort of echo?" In this case I was adding caching to my
application. I had not used it before, so I placed an echo for "$auth cache
created" into my code. During development I find it helpful. In this case,
with a cache set to have a life of two hours, it threw me for a loop. Every
once in a while (each time the cache needed to be refreshed) I ran into this
error that I couldn't replicate, or at least that I couldn't replicate for
another two hours. This isn't something I plan on doing in a production
environment, so this solves my problem.
I'll haven't yet invested the time to learn about exception handling. This
seems like something I'd throw into a log file rather then displaying on the
screen.
Jim
GavinZend wrote:
Hi Jim,
Ok, in your case the "headers already sent" message seems unrelated to
Zend_Session.
Since _redirect() adds a "Location" HTTP header to the response object,
and, by default,
sends the HTTP headers in the response object before exit()'ing, why use
"some sort of echo"
before calling $this->_redirect()?
The headers_sent() function can be used to help precisely locate
accidental output sent before the headers:
http://www.php.net/headers_sent
Cheers,
Gavin
Jim Scherer wrote:
I am using 8.0, not sure what revision but I updated it within the last
three
days. My error occurs from a $this->_redirect('/') in my
AuthorizeController
(Zend_Controller_Action). It only occurs if I have done some sort of echo
anytime previous to the $this->_redirect('/'). If I'm not performing a
$this->_rediect('/') the echo doesn't seem to matter. Hopefully that
helps.
Jim
PHP/Linux/Apache/etc
GavinZend wrote:
There are several possible reasons for this, including both Zend_Session
related and non-ZF related.
Which version of the ZF are you using?
Which method/function call is the immediate cause of the "Cannot modify"
message?
Cheers,
Gavin
Jim Scherer wrote:
Hi,
I've been getting the 'Cannot modify header information - headers
already
sent ' on my hosted server for the last couple of days but not on a
local
server, and for the life of me couldn't figure out why. At least now I
understand why I get it on one and not the other. I also get mine
during
authentication. I recently added caching to my application and thought
that
it somehow was related, but I wasn't able to pinpoint it. Hopefully
someone
knows what is going on. Thanks for the post, this was bothering me.
Jim