PHP:我得到一个完全空白的页面,我不知道如何在 PHP 中调试它

发布于 2024-09-09 06:42:32 字数 196 浏览 6 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

救赎№ 2024-09-16 06:42:32

通常,当您收到 WSOD(死机白屏)时,这是因为存在致命错误,并且它没有显示在标准输出(即生成的页面)上。

要显示它,您需要:

一个简单的方法是在 PHP 脚本的顶部执行此操作,使用如下代码部分一:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

在您的具体情况下,您尝试通过 HTTP 包含/要求某些内容;这通常被禁用。

请参阅allow_url_include指令,关于这一点。

一种可能是在 PHP 配置中启用该功能...但通常不认为这是一个好主意:出于安全原因将其禁用。

发送包含文件的 HTTP 请求的速度很慢,这意味着如果远程服务器不响应,您的应用程序将无法再工作!

另外,在这里,您尝试包含来自远程服务器的文件 $_SERVER["HTTP_HOST"]...

... 因此,您尝试包含来自远程服务器的文件事实上,那是您自己的服务器?即不是远程的?

如果是这样,您不应该尝试通过 HTTP 包含;相反,您应该使用本地文件;这样(需要一些调整)

require_once dirname(__FILE__) . "/dompdf/dompdf_config.inc.php";

这样:

  • 没有不需要的网络请求(您只需从本地磁盘读取) =>更快、更安全
  • ,无需启用 allow_url_include

我还应该补充一点:

  • 当包含本地 .php 文件时,.php 文件的内容将包含在您的页面中;就像复制粘贴一样
  • 当通过 HTTP 包含 .php 文件时,远程服务器很可能会解释 PHP 代码,并且只向您发送输出
    • 这意味着您的脚本中不会包含 PHP 代码
    • 但只有通过执行 PHP 代码获得的输出!

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 :

An easy way is to do that at the top of your PHP script, with a portion of code like this one :

error_reporting(E_ALL);
ini_set('display_errors', 'On');

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) :

require_once dirname(__FILE__) . "/dompdf/dompdf_config.inc.php";

This way :

  • No network un-needed request (you'll just read from the local disk) => faster and safer
  • And no need to enable allow_url_include

I should also add :

  • When including a local .php file, the content of the .php file is included in your page ; like if it's copy-pasted
  • When including a .php file via HTTP, chances are that the remote server will interpret the PHP code, and only send you the output back
    • Which means it's not the PHP code that will get included by your script
    • But only the output you'd get by executing that PHP code !
栖竹 2024-09-16 06:42:32

您不应该要求/包含这样的远程文件。相反,提供本地绝对或相对路径。

尽管不安全且不推荐,但如果设置了某些配置选项,那么从技术上讲是可以做到的。 (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.

俯瞰星空 2024-09-16 06:42:32

这是一种非常不寻常且不安全的包含文件的方式,但是如果您仍然想使用它,请确保您包含的文件没有在远程服务器上执行,因为您可能将 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.

天气好吗我好吗 2024-09-16 06:42:32

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.

听,心雨的声音 2024-09-16 06:42:32

尝试将其添加为脚本的第一行(显然在

error_reporting(E_ALL);

Try adding this as the first line of your script (after the <?php obviously):

error_reporting(E_ALL);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文