所有 PHP 页面都需要添加 ob_start() 前缀
是否可以将 ob_start()
放在所有 PHP 页面的开头?
如果我不这样做,我会收到“标头已发送”错误。
Is it OK to have ob_start()
in the beginning of all PHP pages?
If I don't do this, I get the "headers already sent" error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是“好的”,但你应该真正修复你的脚本,以免过早输出内容并将输出保存到最后。但是您可以更改
.htaccess
或php.ini
中的设置,下面是 .htaccess 的设置:在我看来,这将是首选,而不是添加 < code>ob_start 到所有脚本的顶部。
但是,您确实应该从根本上解决问题。 IE:保存脚本末尾的输出。
It is "ok" but you should really fix your script to not output stuff prematurely and save the output for the end. But you can just change a setting in
.htaccess
or thephp.ini
the below is the for .htaccess:This would be preferred, in my opinion, instead of adding
ob_start
to the top of all your scripts.However, you really should fix the problem at its core. IE: Save output for the end of the script.
您可能页面顶部之前有空格
这将导致错误“HEADER ALREADY SEND”
不知道 ob_start()
you may have white space before at the top of page
This will lead that error "HEADER ALREADY SEND "
No idea about ob_start()
我想说,可以将其作为一种解决方法,或者只是快速使现有脚本工作。然而从长远来看,您应该考虑重新设计您的应用程序,这样就不会发生这样的事情。一般来说,您应该尝试完全分离应用程序逻辑和输出。
I would say it is okay to do this as a workaround or when simply quickly making your existing script work. In the long run however you should think about redesigning your application so things like this don't happen. In general you should try to completely separate application logic and the output.