So, Iām trying to check if the Apache server name contains a certain string, and noticed a very strange behavior (for example, no matches in the if statement, even if the lines turned out to be exactly the same). Using var_dump(), I looked at my variable containing the server name, and, to my surprise, I saw this:
string(11) "test.local:5757"
The string contains only 11 characters if you do not count the numbers. If I declare a variable with 'test.local:5757'instead $_SERVER['SERVER_NAME'], I get the correct length, 15.
I tried adding an empty line to the end of the "reset" line, I even tried adding extra letters to the line, which eventually counted, but 5757 is still not counted.
Has anyone ever experienced this?
Edit: Sorry, it happened after posting that I did not add enough information.
One of the main details that I forgot is that I use CodeKit on top of MAMP. My local MAMP installation is in localhost, and my code project is CodeKit test.local:5757'. However, it looks like port 5757 is displayed when I repeat the variable declared as $_SERVER['SERVER_NAME']. Even stranger is the fact that the echo $_SERVER['SERVER_NAME'] . ':' $_SERVER['SERVER_PORT']prints test.local:5757, when you change the colon to any other character, for example $_SERVER['SERVER_NAME'] . '>' $_SERVER['SERVER_PORT'], prints test.local:5757>80.
Here are some more examples of what I see:
$host = $_SERVER['SERVER_NAME'];
echo $host;
$host = $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
echo $host;
$host = $_SERVER['SERVER_NAME'] . '&' . $_SERVER['SERVER_PORT'];
echo $host;
$host = $_SERVER['SERVER_NAME'];
echo $host;
$bool = false;
if ($host == 'test.local:5757') $bool = true;
echo $bool;
$host = $_SERVER['SERVER_NAME'];
var dump($host);
Sorry for not being marked as related to CodeKit. Any help is much appreciated!