Set a variable according to the server_name

Some time ago I asked this question, but that thread was closed (after 3 months). Today I believed to have found the answer, that is

if ($_SERVER['SERVER_NAME'] = "localhost")
{$yourwebsiteA = "http://localhost/your path/yourwebsiteA/";
 $yourwebsiteB = "http://localhost/your path/yourwebsiteB/";
 $yourwebsiteC = "http://localhost/your path/yourwebsiteC/";
}
else 
{$yourwebsiteA = "http://remote path/yourwebsiteA/";
 $yourwebsiteB = "http://remote path/yourwebsiteB/";
 $yourwebsiteC = "http://remote path/yourwebsiteC/";
}

This code works for the if part, but not for the else one: in remote I have still a localhost value, even server_name is not localhost.
Where I’m wrong?

You miss a equal sign…

2 Likes

Perfect!!
Thank you very much!

Even better would be three equal signs, to make sure both are strings

if ($_SERVER['SERVER_NAME'] === "localhost")

I’ve put == on my personal list of things not to use as it is way too unpredictable.

Just check all the things that are considered to equal here: https://phpcheatsheets.com/compare/

1 Like

Done! Thank you!