Full URL not working with php include

前端 未结 6 1824
闹比i
闹比i 2020-12-07 03:55

So, I am trying to insert a file with a php include, but for some reason it doesn\'t work with the full URL.

This works:

相关标签:
6条回答
  • 2020-12-07 04:24

    Does your php.ini allow you to use remote files with include?

    If it's on your own domain then it makes no sense to require the absolute URL, as this would cause the server to open a connection to itself to retrieve the file via HTTP when a direct file operation would be so much simpler.

    0 讨论(0)
  • 2020-12-07 04:31

    An include tag is meant to be used to reference other PHP script files. If it is not a script that you are going to be processing, you might want to look into using:

    $FileContents = file_get_contents("http://www.domainname.com/menu.html");
    
    0 讨论(0)
  • 2020-12-07 04:36

    include is meant to include and evaluate a specified PHP file. If you fetch it locally, it can be processed like PHP - if you fetch it through a full URL, you will get the resulting HTML (in theory ... you may get only an error).

    Supporting Docs

    include 'menu.php' //Internally process a PHP file to generate HTML
    

    or

    file_get_contents('http://domainname.com/menu.php'); //Fetch resutling HTML
    
    0 讨论(0)
  • 2020-12-07 04:37

    Don't use absolute urls. Instead, try linking from the root directory. Like this:

    $path = $_SERVER['DOCUMENT_ROOT']."/layer1/layer2/layer3/";
    include($path."file.php");
    
    0 讨论(0)
  • 2020-12-07 04:38

    Sounds like allow_url_fopen or allow_url_include or both have been set to 0 (disabled) in php.ini.

    HTML should't be included in a PHP script, though. Other answers seem to address that issue as well.

    0 讨论(0)
  • 2020-12-07 04:42

    check php.ini -

    allow_url_include

    but I have to say, if you don't have really really good reason, please don't use it. It's one of the worst php weaknesses, serious security threat.

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