【问题标题】:PHP include a file at subdomain from main domain on a different server/hostPHP在不同服务器/主机上的主域中包含子域中的文件
【发布时间】:2023-03-17 11:59:01
【问题描述】:

我有这个 php

www.example.com/template.php

并希望将其包含在 index.php 文件中

sub.example.com/index.php

并且此子域位于具有不同主机的不同服务器上。

请指教。

【问题讨论】:

  • /path/to/index.php 所以像 /www/public_html/index.php

标签: php include server-side-includes


【解决方案1】:

您可以将文件内容下载到 php 文件中,然后将其包含在内,

$url = "http://sub.example.com/index.php";
$file = file_get_contents($url);
file_put_contents('index.php', $file);
include index.php;

我建议更改 index.php 的名称,并确保在获取 php 文件时不会先对其进行解析。

这也没有什么安全的。

编辑:另一种选择,

有一个名为 allow_url_include 的 php.ini 选项。

http://php.net/manual/en/features.remote-files.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-23
    • 2015-02-02
    • 1970-01-01
    • 2015-06-04
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多