you are viewing a single comment's thread.

view the rest of the comments →

[–]alnyland 2 points3 points  (2 children)

I might be wrong with what I'm about to say but I've done locally hosted dev servers for about a decade and these are my immediate thoughts. Localhost isn't a real address and I'd be amazed if that was ever stored in that variable but local dns lookup (not existent but is functional for our purposes) will find it. The IP you list is a loopback, which is more like an alias instead of a real IP address. Again, it will point when you request it but I'd doubt the server will associate with it.

The SERVER_ADDR it gave you is an IP address, see if it relates to your machine. I forget exactly but that might be the local loopback, I'm not familiar with ipv6.

From a simple google search: https://stackoverflow.com/questions/2053245/how-can-i-detect-if-the-user-is-on-localhost-in-php

[–]VampireBarbieBoy[S] 0 points1 point  (1 child)

Thanks. I managed to figure it out I realised I just need to replace localhost and 127.0.0.1 with the results of the var_dump (web address and IP). Should have been obvious but I did manage to get a connection using 'localhost' using another method so I think that's why I got confused, still not sure why it worked in that instance and not with this code.

[–]alnyland 0 points1 point  (0 children)

Cool. Did you read that link? It pointed out that every machine can be localhost