New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web/Response::sendHeaders does not warn if headers are already send #15046
Comments
Had same issue, just forgot to put $this->beginPage() in layout file. |
@cronfy please do. |
So, now you can't call VarDumper in action. Because of: |
@irthunder hmm, I usually call |
@cronfy Sometimes you need, sometimes you don't. But this definitely will broke projects, who using (can use) |
@irthunder Yes, of course, if I do not need it, it does not mean everybody do not need it too. I just was wondering why I never met issue you mentioned. I see the problem about REST apps with But. Usually PHP sends a warning when trying to send headers after they were sent:
It protects from hard-to-debug bugs when session does not start, cookies not sent etc. But in
Without this check
Any other ideas to solve this? |
I has my own function which sends some headers (custom csv renderer for specific purposes). |
I just ran into this change when using Imagine to render images, because they call the imagepng() etc function directly returning it into Yii2 response actually creates errors now. One method to solve this is to wrap the output ion ob() |
@insperedia God, I've been checking this issue for hours, it turn out to be not having a $this->beginPage() in layout file, you save my ass man. |
I'm suggesting to do this: |
I experienced problems with CSRF similar to #541 #7115 . CSRF cookie just was not sent in response to requests.
It turned out that one of my files echoed some content before
View::beginPage()
call.To find it, I had to debug through all the application up to Response::sendHeaders(), where I could find the root cause of the issue dumping
$file
and$line
fromheaders_sent($file, $line)
.The question is: why Yii does not warn/throw an error if headers were already sent prior to
Response::send()
? This leads to silent and hard-to-debug problems.I think simple check before
$this->sendHeaders()
inResponse::send()
, that will throw an Exception ifheaders_sent)
is true, will solve this issue.I can make a PR for this if this solutuion is ok.
The text was updated successfully, but these errors were encountered: