gc40 Posted February 8, 2009 Share Posted February 8, 2009 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 https://forums.phpfreaks.com/topic/144351-server_name-conflicts-within-localhost-and-live-environment/ Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 str_replace("www.","",$hostname); Link to comment https://forums.phpfreaks.com/topic/144351-server_name-conflicts-within-localhost-and-live-environment/#findComment-757476 Share on other sites More sharing options...
premiso Posted February 8, 2009 Share Posted February 8, 2009 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 https://forums.phpfreaks.com/topic/144351-server_name-conflicts-within-localhost-and-live-environment/#findComment-757480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.