output_buffering 和 php.ini 的问题
当尝试登录此站点(用户:polopolo,pass:samara)时,结果是空白页。 我知道问题出在 php.ini 文件中的标头发送和 ouput_buffering 上。 我在另一台主机上遇到了同样的问题,但当我更改 output_buffering= On 时,问题得到了解决。 它在当前主机上不起作用,我想知道为什么? 有什么建议么?
- 当前站点的phpinfo。
编辑: 问题解决了。 我对代码进行了逆向工程,发现在 php 结束标记之后、发送标头之前有一些额外的空格。 该代码不是我写的,我本能地忽略了这个选项,因为整个系统已经在另一台服务器上运行了。 但我的同事做了一些我没有意识到的改变……吸取的教训:团队合作很重要,不要让任何人替你思考。 对我来说仍然是一个谜,在尝试了所有显示错误的方法之后,尤其是“无法修改标题”,它们为什么没有正确显示。 我做了你建议我做的一切——显示错误、记录错误等等……无论如何,谢谢。
when trying to log-in at this site (user:polopolo,pass:samara) the result is a blank page. I know that the problem is with the sending of headers and the ouput_buffering in the php.ini file. I had the same problem on another host but the problem was fixed when I changed output_buffering= On. It doesn't work on the current host and I wonder why? Any suggestions?
-the phpinfo of the current site.
Edit:
Problem solved. I reverse-engineered the code and found some additional spaces after the php closing tag, before the sending of the headers. The code wasn't written by me and I instinctively ignored this option as the whole system worked already on another server. But my colleague did some changes I was unaware of...The lesson learned: teamwork is important and don't let anybody do the thinking for you. Still it is a mystery to me how come after trying everything to display errors and especially the "Cannot modify headers" they didn't display properly. I did everything you advised me to do- display errors, log them and so on...anyway thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据推测,您登录后立即访问的页面会进行重定向。
执行重定向需要输出带有响应的 HTTP 标头。 问题是,如果 PHP 已经开始输出文档的正文,则它无法输出标头,因为标头在正文开始时结束。
输出缓冲可防止 PHP 输出文档正文的任何部分,直到输出缓冲区被刷新(或 PHP 退出)。 这允许您随时输出标头。
现在,如果打开输出缓冲可以解决自己站点/服务器上的问题,但不能解决另一个站点/服务器上的问题,那么这清楚地表明它实际上不是同一个问题 - 您遇到了不同的问题。
您应该记录 PHP 错误,因此请检查 PHP 错误日志。 如果(且仅当)您在仅限开发人员的受限制站点(您不是)上查看此内容,您可以在 PHP 配置中打开 display_errors,这将在页面呈现时显示错误。 这通常被认为是可公开访问的服务器上的不安全设置,因为攻击者可能会尝试导致错误,而错误消息会泄露一些私人信息。
Presumably, the page you hit immediately after logging in does a redirect.
Doing a redirect requires outputting an HTTP header with the response. The problem is, if PHP has already begun outputting the body of the document, it cannot then output a header because they headers ended when the body started.
Output buffering prevents PHP from outputting any part of the body of the document until the output buffer is flushed (or PHP exits). This allows you to output headers at any time.
Now, if turning output buffering on fixed the problem on own site/server, but not on another, that's a clear indication that it isn't actually the same problem - you are encountering a different problem.
You should be logging PHP errors, so check your PHP error log. If (and only if) you are viewing this on a restricted developers-only site (which you aren't), you may turn on display_errors in your PHP configuration, which will display errors on the page as it is rendered. This is generally considered an unsafe setting on publicly accessible servers, because of the potential for attackers to try and cause an error for which the error message reveals some private information.
我不是专家,我无法理解输出缓冲与任何事情有什么关系,也许代码中存在一些错误?
您能否创建一个包含以下内容的 .htaccess 文件:
将其放在该站点的根文件夹中,然后尝试再次登录以查看是否有任何输出错误?
I'm no expert and I can't understand what output buffering as to do with anything, maybe there are some errors in the code?
Could you create an .htaccess file with the following content:
Place it in the root folder of that site and then try to log in again to see if there are any output errors?
我在做项目时也遇到了同样的问题。 我后来通过设置修复了它
php.ini 配置文件中的output_buffering = 4096 在本地主机中工作正常,但是当我将其放在主机服务器上时,我再次收到此错误。 我不确定如何在主机服务器上使用我自己的 php.ini 配置文件。 任何建议都欢迎...
I had also got the same problem while working on a project. I fixed it later by setting
output_buffering = 4096 in php.ini configuration file and it worked fine in localhost but when i put it on host server, i got this error again. I am not sure how to use my own php.ini configuration file on host server. Any suggestion are welcome...