如何将文件从主域包含到子域

时间:2021-03-29 16:27:31

标签: php include ini-set

想要将文件从主域包含到子域

index.php - subdomain.example.com

ini_set("allow_url_fopen", 1);
ini_set("allow_url_include", 1);    
$host = $_SERVER['HTTP_HOST'];
if($host == 'localhost'){include("../navt.php");}
else{include("https://example.com/navt.php");}

在本地主机上 - 没有问题(win 10、xampp、chrome)
在远程服务器上 - 我仍然得到这个:
include(): https:// wrapper is disabled in the server configuration by allow_url_include=0

1 个答案:

答案 0 :(得分:1)

documentation for the allow_url_include setting 包含两个重要细节:

  • 只能在“PHP_INI_SYSTEM”级别更改,即explained elsewhere in the manual。它不能在运行时设置,也不能由共享服务器上的个人用户设置。
  • 自 PHP 7.4 起已弃用。

两者都是出于相同的原因:此设置极其危险。强烈建议您考虑如何部署代码,为您的问题提出替代解决方案。例如:

  • 将需要在不同子域之间共享的文件放在磁盘上的某个位置,并使用普通(非 URL)include 引用这些文件。
  • 创建一个可以一次性部署到所有子域的共享库。
  • 对所有子域使用相同的应用程序,并使用代码检测正在显示的是哪个。
相关问题