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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.