Set a variable according to the server_name – PHP – SitePoint Forums

Set a variable according to the server_name – PHP – SitePoint Forums


Some time ago I asked this question, but this thread was closed (after 3 months). Today I thought I had 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 if part, but not for the else one: on remote I still have one localhost value, even server_name is not localhost.
Where am I wrong?


Perfect !!
Thank you so 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 to-do list because it’s too unpredictable.

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



1 I like it



Source link

Related post

EDUCAUSE 2022: How Data Collection Can Improve Student and Faculty IT Support

EDUCAUSE 2022: How Data Collection Can Improve Student and…

At Indiana University, Gladdin said, to make life easier for students and faculty, they implemented a course template for the Canvas…
UGC, AICTE warn students against online PhD programmes offered by EdTech platforms | Latest News India

UGC, AICTE warn students against online PhD programmes offered…

The University Grants Commission (UGC) and the All India Council for Technical Education (AICTE) on Friday issued a joint advisory against…
UGC, AICTE warn students against online PhD programmes offered by EdTech platforms | Latest News India

UGC, AICTE warn students against online PhD programmes offered…

The University Grants Commission (UGC) and the All India Council for Technical Education (AICTE) on Friday issued a joint advisory against…

Leave a Reply

Your email address will not be published.