在 PHP 中包含一个远程文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1158348/
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
including a remote file in PHP
提问by Gaurav Sharma
I am unable to include a remote PHP file in my PHP script. I suppose my hosting changed php settings.
我无法在我的 PHP 脚本中包含远程 PHP 文件。我想我的主机更改了 php 设置。
The code I was using was:
我使用的代码是:
include "http://domain.com/folder/file.php";
How do I allow enable the include function using php.ini/.htaccess ?
如何允许使用 php.ini/.htaccess 启用包含功能?
Is there any other workaround?
还有其他解决方法吗?
Thanks.
谢谢。
回答by Pascal MARTIN
To allow inclusionof remote files, the directive allow_url_includemust be set to Onin php.ini
要允许包含远程文件,allow_url_include必须On在 php.ini 中将该指令设置为
But it is bad, in a security-oriented point of view ; and, so, it is generally disabled (I've never seen it enabled, actually)
但从面向安全的角度来看,这很糟糕;因此,它通常被禁用(实际上我从未见过它启用)
It is not the same as allow_url_fopen, which deals with opening (and not including) remote files -- and this one is generally enabled, because it makes fetching of data through HTTP much easier (easier than using curl)
它与allow_url_fopen处理打开(但不包括)远程文件的 不同 - 通常启用这个,因为它使通过 HTTP 获取数据更容易(比使用 curl 更容易)
回答by Paul Dixon
To use remote includes, the allow_url_fopenand allow_url_includeoption must be set in php.ini
要使用远程包含,必须在 php.ini 中设置allow_url_fopen和allow_url_include选项
Be aware that if the remote server is php-enabled, you'll get the outputof that remote script, not the script itself. If you do want to fetch the source, you could add a symlink on the remote server, e.g. ln -s file.php file.php.sourceand then make your include reference file.php.source instead.
请注意,如果远程服务器启用了 php,您将获得该远程脚本的输出,而不是脚本本身。如果你确实想获取源代码,你可以在远程服务器上添加一个符号链接,例如ln -s file.php file.php.source,然后让你的包含引用 file.php.source 代替。

