简体   繁体   English

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

[英]how to to include a file from main domain to subdomain

want to include a file from main domain to subdomain想要包含从主域到子域的文件

index.php - on subdomain.example.com 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");}

on localhost - there is no problem (win 10, xampp, chrome)在本地主机上 - 没有问题(win 10,xampp,chrome)
on remote server - I'm still getting this:在远程服务器上 - 我仍然得到这个:
include(): https:// wrapper is disabled in the server configuration by allow_url_include=0

The documentation for the allow_url_include setting includes two important details: allow_url_include设置的文档包括两个重要的细节:

  • It is changeable at "PHP_INI_SYSTEM" level only, which is explained elsewhere in the manual .它只能在“PHP_INI_SYSTEM”级别更改, 手册中其他地方对此进行了说明 It cannot be set at run-time, nor by individual users on a shared server.它不能在运行时设置,也不能由共享服务器上的单个用户设置。
  • It is deprecated since PHP 7.4.自 PHP 7.4 起已弃用。

Both of these are for the same reason: this setting is extremely dangerous .这两者都是出于同样的原因:这个设置非常危险 It's highly advisable to come up with an alternative solution to your problem, by thinking about how you deploy your code .通过考虑如何部署代码来为您的问题提出替代解决方案是非常可取的。 For instance:例如:

  • Put the files that need to be shared between the different sub-domains somewhere on disk, and reference those files with a normal (non-URL) include .将需要在不同子域之间共享的文件放在磁盘上的某个位置,并使用普通(非 URL) include引用这些文件。
  • Create a shared library that you can deploy to all the sub-domains at once.创建一个共享库,您可以一次将其部署到所有子域。
  • Use the same application for all the sub-domains, with code to detect which one is being displayed.对所有子域使用相同的应用程序,并使用代码检测正在显示的子域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM