I am writing my config file and I often work between localhost and the live server.
$hostname = $_SERVER['SERVER_NAME'];
if ($hostname == 'localhost')
{
$host = 'localhost';
$user = 'root';
$pass = 'rootpass';
$database = 'default_db';
}
else if($hostname == 'domain.com')
{
$host = 'localhost'; // Name of server you are on (e.g. localhost)
$user = 'live_user'; // Your Server Username
$pass = 'live_password'; // Your Server Password
$database = 'live_db'; // Database Name where the user details are
}
The only problem with the above is if the client is visiting www.domain.com then hostname = www.domain.com
If the client visits http://domain.com then hostname = domain.com
How do I go about removing the www. without affecting none www. names?