Reputation: 40140
How do I read the server host fromPHP.init?
I want to copy a site from my localhost
to a production sever and have it work without having to change any code. I figurd that this would be the best way to do it
Upvotes: 0
Views: 803
Reputation: 5191
Use the ini file from the production server in your development environment to avoid any surprises when you move your code from dev to production. If you need to do something differently in your code see if
$_SERVER['HTTP_HOST']
is set and, if it is, extract the domain and do whatever you need to based on the value of the domain.
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
}
Upvotes: 1