如何从PHP.init读取服务器主机?
我想把一个网站从我的localhost
复制到生产服务器上,让它在不更改任何代码的情况下工作。我认为这将是最好的方法
在开发环境中使用生产服务器中的ini文件,以避免在将代码从开发转移到生产时出现任何意外。如果你需要在你的代码中做一些不同的事情,看看
$_SERVER['HTTP_HOST']
设置,如果是,则提取域并根据域的值执行所需的操作。
if (isset($_SERVER['HTTP_HOST'])) {
$hostbu = explode('.',$_SERVER['HTTP_HOST']);
$domain = $hostbu[(count($hostbu) - 2)] . '.' . $hostbu[(count($hostbu) - 1)];
} else {$domain = '';} // end of if the server variable HTTP_HOST is set; else set domain to null
// we are NOT on the development machine
// change the logic to see if you are on the production machine depending on your needs
if ($domain != 'devdomain.com') {
spl_autoload_extensions(".class"); // may be a comma-separated list of extensions
spl_autoload_register();
// do anything else you need to do here
}