Php 根据域名加载不同的配置文件
我想能够加载一个不同的配置文件基于域名使用纯PHP 当前,我的配置文件使用以下方式加载Php 根据域名加载不同的配置文件,php,Php,我想能够加载一个不同的配置文件基于域名使用纯PHP 当前,我的配置文件使用以下方式加载 # Look for a config.php in the /themes/themeName/ folder if ( ! defined('MULTI') && file_exists($tmp = WWW_ROOT . '/themes/' . $CONFIG['theme'] . '/config.php') ) { 但我需要能够添加域是否是/theme/domain1中的doma
# Look for a config.php in the /themes/themeName/ folder
if ( ! defined('MULTI') && file_exists($tmp = WWW_ROOT . '/themes/' . $CONFIG['theme'] . '/config.php') ) {
但我需要能够添加域是否是/theme/domain1中的domain1.com加载配置,或者是否是/theme/domain2中的domain2.com加载,以及是否不是从/theme/default加载的这些域
当一个域名停在另一个域的顶部时,使用此选项,这样除了配置文件外,内容都是相同的
我在想一些关于
if ($_SERVER['HTTP_HOST']="domain1.com")
else if ($_SERVER['HTTP_HOST']="domain2.com")
else
只是不确定如何正确格式化,或者这是最好的方式
if (isset($_SERVER['HTTP_HOST']) && file_exists(WWW_ROOT . '/themes/' . $_SERVER['HTTP_HOST'] . '/config.php')
include(WWW_ROOT . '/themes/' . $_SERVER['HTTP_HOST'] . '/config.php');
else
include(WWW_ROOT . '/themes/default/config.php');
我认为direct include$\u SERVER['HTTP\U HOST']不是很好 为什么不制作一个特定于域的
config.php
文件上传到每个域?所有域上都有相同的内容,只是每个域的广告代码放置/发布ID等内容需要不同而已。但是我希望能够从一个源加载所有这些域,这样我就可以有很多域都停在一个域上。这看起来很完美,它应该加载配置文件,如果它存在的域,否则加载默认值。我实际上要使用你上面发布的第一部分和这个问题的其他答案,因为我喜欢列出域和文件夹名称,就像你做的那样。谢谢
$themes_path=array(
'domain1.com'=>'foldername1',
'domain2.com'=>'foldername2'
);
if (isset($_SERVER['HTTP_HOST']) && file_exists(WWW_ROOT . '/themes/' . $themes_path[$_SERVER['HTTP_HOST']] . '/config.php'){
include(WWW_ROOT . '/themes/' . $themes_path[$_SERVER['HTTP_HOST']] . '/config.php');
}