完整的 URL 不适用于 php 包括
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13369529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Full URL not working with php include
提问by ultraloveninja
So, I am trying to insert a file with a php include, but for some reason it doesn't work with the full URL.
所以,我试图插入一个包含 php 的文件,但由于某种原因,它不适用于完整的 URL。
This works:
这有效:
<?php include 'menu.html' ?>
<?php include 'menu.html' ?>
But this does not:
但这不会:
<?php include 'http://domainname.com/menu.html' ?>
<?php include 'http://domainname.com/menu.html' ?>
Any ideas?
有任何想法吗?
回答by Zdenek Machek
check php.ini -
检查 php.ini -
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.
但我不得不说,如果你没有真正很好的理由,请不要使用它。这是 php 最严重的弱点之一,严重的安全威胁。
回答by Niet the Dark Absol
Does your php.iniallow you to use remote files with include?
您是否php.ini允许您使用远程文件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.
如果它在您自己的域中,那么要求绝对 URL 是没有意义的,因为这会导致服务器打开与自身的连接以通过 HTTP 检索文件,而直接文件操作会简单得多。
回答by Dutchie432
includeis 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).
include旨在包含和评估指定的 PHP 文件。如果你在本地获取它,它可以像 PHP 一样处理——如果你通过一个完整的 URL 获取它,你将得到结果 HTML(理论上......你可能只会得到一个错误)。
include 'menu.php' //Internally process a PHP file to generate HTML
or
或者
file_get_contents('http://domainname.com/menu.php'); //Fetch resutling HTML
回答by Matt Clark
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:
包含标记旨在用于引用其他 PHP 脚本文件。如果它不是您要处理的脚本,您可能需要考虑使用:
$FileContents = file_get_contents("http://www.domainname.com/menu.html");
回答by Rayyan Ahmed
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");
回答by Rayyan Ahmed
Sounds like allow_url_fopenor allow_url_includeor both have been set to 0 (disabled) in php.ini.
像声音allow_url_fopen或allow_url_include或二者都被设置为0(关闭)的php.ini。
HTML should't be included in a PHP script, though. Other answers seem to address that issue as well.
但是,HTML 不应该include在 PHP 脚本中出现。其他答案似乎也解决了这个问题。

