I am confused. I had set up the following code in my index.php to auto switch between xampp and server database config files:
define('ENVIRONMENT', isset($_SERVER['SERVER_NAME'])=='my_domain_name.com' ? 'production' : 'development');
echo 'SERVER_NAME '.$_SERVER['SERVER_NAME']; // getting localhost
echo 'env '.ENVIRONMENT; // getting production.
In Xampp locally, I thought this would result in the ENVIRONMENT constant set to ‘development’ with $_SERVER[‘SERVER_NAME’]=localhost. Would someone mind explaining what I’m doing wrong here?
Here you’re comparing the result of
isset()to'my_domain_name.com'; you’re comparing a boolean to a string.What you want is to check “is
$_SERVER['SERVER_NAME']set AND is$_SERVER['SERVER_NAME']equal tomy_domain_name.com?“, as follows:(Or… just remove the
isset()entirely.)