I want to create a function on my functions.php that checks whether I'm on a local setup (url is http://macbook.local:5757/) or a live server (example.com).
Here is my code:
$server = $_SERVER["HTTP_HOST"];
if (strpos($server,'macbook') !== false) {
echo 'true ';
echo $server;
} else {
echo 'false ';
echo $server;
}
It outputs:
"false macbook.local:5757"
If I edit the code and put:
//$server = $_SERVER["HTTP_HOST"];
$server = "macbook.local:5757";
if (strpos($server,'macbook') !== false) {
echo 'true ';
echo $server;
} else {
echo 'false ';
echo $server;
}
I get: "true macbook.local:5757"
Why does the other one work when the other doesnt? They look like the same string. I'm probably missing something elementary here. I'm using a similar setup on wp-config.php to set database credentials depending on whether the site is local or live and it works there.
Thank you!
EDIT: If I use
var_dump($server);
it outputs:
false-string(17) "macbook.local:5757"