including php file from another server with php(使用 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 php 包括来自另一台服务器的 php 文件


基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01