根据域名加载不同的配置文件



我希望能够使用纯PHP基于域名加载不同的配置文件。

目前我的配置文件加载使用以下

# Look for a config.php in the /themes/themeName/ folder
if ( ! defined('MULTI') && file_exists($tmp = WWW_ROOT . '/themes/' . $CONFIG['theme'] . '/config.php') ) {

但我需要能够添加如果域是domain1.com加载配置从/theme/domain1或如果它是domain2.com加载从/theme/domain2,如果它不是这些域加载从/theme/default。

当一个域名停在另一个域名的顶部,所以内容都是一样的,除了配置文件。

我在想一些类似

的东西
if ($_SERVER['HTTP_HOST']="domain1.com")
else if ($_SERVER['HTTP_HOST']="domain2.com")
else

只是不确定如何正确格式化,或者这将是最好的方式。

$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');
}

我认为直接包含$_SERVER['HTTP_HOST']不是很好。

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');

最新更新