包括来自php的其他服务器的php文件 [英] including php file from another server with php
问题描述
我有两个PHP文件位于不同的服务器上,一个位于 http://www.mysite.com/main.php
,另一个位于 http://www.sample.com/includeThis.php
。
我想包括第一个文件。 / p>
第二个文件的内容如下所示:
?php
$ foo =这是来自文件1的数据;
第一个文件:
<?php
includehttp://www.sample.com/includeThis.php;
echo $ foo;
有没有办法这样做?
不,默认情况下,大多数Web服务器(php.ini)禁用/禁止此设置,因此您不能使用 include
以包含来自远程地址的文件安全性原因。
如果您还想允许包含的远程文件,指令 allow_url_include
必须设置为在php.ini中的
但再次是不良做法,以安全为导向的观点;因此,它通常是禁用的(实际上我从来没有看到它启用)
如果您想要读取远程文件的内容, / strong>,您可以使用 file_get_contents
功能而不是但是这将作为纯HTML标记代码返回,不会有任何服务器端代码。
I have two PHP files located on different servers, one at http://www.mysite.com/main.php
, the other at http://www.sample.com/includeThis.php
.
I want to include the second file from the first one.
The content of the second file looks like this:
<?php
$foo = "this is data from file one";
And the first file:
<?php
include "http://www.sample.com/includeThis.php";
echo $foo;
Is there any way I can do this?
Nope, this setting is disabled/not allowed by default in most web servers (php.ini) so you can not use the include
to include the files from a remote addresss for security reasons.
If you still want to allow inclusion of remote files, the directive allow_url_include
must be set to On
in php.ini
But again it is a bad practice, in a security-oriented point of view ; and, so, it is generally disabled (I've never seen it enabled, actually)
If you want to read the contents of a remote file though, you can use the file_get_contents
function instead BUT this will be returned as pure HTML markup code, there won't be any server-side code.
这篇关于包括来自php的其他服务器的php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!