PHP: I get a completely blank page, I don't know how to debug this in PHP

后端 未结 5 732
执笔经年
执笔经年 2021-01-22 06:04

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\");
         


        
相关标签:
5条回答
  • 2021-01-22 06:09

    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 :

    • set error_reporting to the right level
    • and enable display_errors

    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 !
    0 讨论(0)
  • 2021-01-22 06:20

    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.

    0 讨论(0)
  • 2021-01-22 06:24

    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.

    0 讨论(0)
  • 2021-01-22 06:30

    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.

    0 讨论(0)
  • 2021-01-22 06:32

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

    error_reporting(E_ALL);
    
    0 讨论(0)
提交回复
热议问题