Jump to content

Server_Name conflicts within localhost and live environment


gc40

Recommended Posts

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?

You could use .htaccess to always redirect to www. which a howto can be found here if you want to force one or the other. If not:

 

$hostname = str_replace("www.", "", $_SERVER['SERVER_NAME']);

 

Should work, however.

 

EDIT:

=\ beaten to it. However, posting for the .htaccess info.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.