使用 php 包含来自另一台服务器的 php 文件 [英] including php file from another server with php

查看:30
本文介绍了使用 php 包含来自另一台服务器的 php 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的服务器上有两个 PHP 文件,一个位于 http://www.mysite.com/main.php,另一个位于 http://www.sample.com/includeThis.php.

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

和第一个文件:

<?php
include "http://www.sample.com/includeThis.php";
echo $foo;

有什么办法可以做到这一点吗?

Is there any way I can do this?

推荐答案

不,在大多数 Web 服务器 (php.ini) 中默认禁用/不允许此设置,因此您不能使用 include 出于安全原因包含来自远程地址的文件.

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.

如果您仍然希望允许包含远程文件,指令allow_url_include 必须在 php.ini 中设置为 On

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)

如果你想读取远程文件的内容,你可以使用file_get_contents 函数代替 BUT 这将作为纯 HTML 标记代码返回,有不会是任何服务器端代码.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆