PHP:我得到一个完全空白的页面,我不知道如何在 PHP 中调试它
我在 php 中调试时遇到一些问题。当我包含这一行时:
require_once("http://" . $_SERVER["HTTP_HOST"] . "/dompdf/dompdf_config.inc.php");
我得到的只是一个空白页面,我没有得到任何 html 代码作为响应。也许错误消息被隐藏了?
I'm having some issues to debug this in php. When I include this line:
require_once("http://" . $_SERVER["HTTP_HOST"] . "/dompdf/dompdf_config.inc.php");
what I get is just a blank page, I don't get any html code as response. Maybe the error messages are hidden ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常,当您收到 WSOD(死机白屏)时,这是因为存在致命错误,并且它没有显示在标准输出(即生成的页面)上。
要显示它,您需要:
error_reporting
到正确的级别display_errors
一个简单的方法是在 PHP 脚本的顶部执行此操作,使用如下代码部分一:
在您的具体情况下,您尝试通过 HTTP 包含/要求某些内容;这通常被禁用。
请参阅
allow_url_include
指令,关于这一点。
一种可能是在 PHP 配置中启用该功能...但通常不认为这是一个好主意:出于安全原因将其禁用。
发送包含文件的 HTTP 请求的速度很慢,这意味着如果远程服务器不响应,您的应用程序将无法再工作!
另外,在这里,您尝试包含来自远程服务器的文件
$_SERVER["HTTP_HOST"]
...... 因此,您尝试包含来自远程服务器的文件事实上,那是您自己的服务器?即不是远程的?
如果是这样,您不应该尝试通过 HTTP 包含;相反,您应该使用本地文件;这样(需要一些调整):
这样:
allow_url_include
我还应该补充一点:
Quite often, when you get a WSOD (white screen of death), it's because there's a Fatal Error, and it's not displayed on the standard output -- i.e. the generated page.
To have it displayed, you need to :
error_reporting
to the right leveldisplay_errors
An easy way is to do that at the top of your PHP script, with a portion of code like this one :
In your specific case, you are trying to include/require something via HTTP ; which is often disabled.
See the
allow_url_include
directive, about that.A possibility would be to enable that one in your PHP's configuration... But it's generally not considered as a good idea : it's disabled for security reasons.
And sending an HTTP request to include a file is slow -- and means your application will not work anymore if the remote server doesn't answer !
Also, here, you are trying to include a file from a remote server that is
$_SERVER["HTTP_HOST"]
...... So, you are trying to include a file from a remote server that is, in fact, your own server ? i.e. not a remote one ?
If so, you should not try to include via HTTP ; instead, you should work with a local file ; this way (will need some tunning) :
This way :
allow_url_include
I should also add :
您不应该要求/包含这样的远程文件。相反,提供本地绝对或相对路径。
尽管不安全且不推荐,但如果设置了某些配置选项,那么从技术上讲是可以做到的。 (allow_url_include)
请参阅下面有关 display_errors 的其他答案,以了解未来的调试问题。我经常使用 PHP 命令行解释器来获取真正的错误,而不允许将错误详细信息呈现给 Web 访问者。
You should not require/include a remote file like this. Instead provide the local absolute or relative path.
Though insecure and not recommended, it is technically possible to do if certain configuration options are set. (allow_url_include)
See other answers below regarding display_errors for future debugging concerns. I often use the PHP command line interpreter to get the real error, without allowing error details to be presented to web visitors.
这是一种非常不寻常且不安全的包含文件的方式,但是如果您仍然想使用它,请确保您包含的文件没有在远程服务器上执行,因为您可能将 require_once 上的 php 源代码作为目标这里不是它的最终输出。
This a very unusual and insecure way to include files, but yet if you still want to use it, make sure that the file you're including isn't being executed on the remote server since you probably targeting the php source code on the require_once here not the final output of it.
require_once
语句的参数应该是文件路径,而不是 URL。您是在告诉 Web 服务器从文件系统导入文件,而不是让客户端从 Web 导入文件。
它记录在包含声明页面上。
The parameter to the
require_once
statement should be a file path, not a URL.You are telling the web server to import a file from the file system, not the client to import the file from the web.
It is documented on the include statement page.
尝试将其添加为脚本的第一行(显然在
Try adding this as the first line of your script (after the <?php obviously):