ID:182370
 
I want a PHP function or built-in variable or something to return the server's IP address (like 71.120.103.159, go ahead and hack me; you can find it by logging into a Byond game I host anyway) in case it changes but all I can find is $_SERVER['SERVER_ADDR'] which returns the local IP of 192.168.0.103 or 'REMOTE_ADDR' which is the IP of the guy with the browser. Does such a function or extravagant workaround exist, or must I just type in '71.120.103.159' everywhere and change it whenever my IP decides to change? =O
You could always poll an external site such as "http://www.whatismyip.com"; those sites are not going to go down anytime soon.
In response to Flame Sage
Polling is not something I am familiar with. I noticed that they have an "automation" tab on whatismyip.com but don't go into any detail on how to "automate". Do I just run a function of some kind with their address as an argument?~
In response to Cowdude
It's quite simple.
You use PHP to grab the information from this webpage.
http://www.whatismyip.com/automation/n09230945.asp
In response to Flame Sage
and what function do I use for that? It's surprisingly hard to find anything like this online unless I already know the function name since "php" is also a file extension and there are like eighty programming languages that people could be trying to do this on. I gave up my search after reading about how to do it in VB, C++, and Python D:
$_SERVER['HTTP_HOST'] is supposed to provide you with the address the request came in on, so if you are behind a NAT (as you appear to be) and the request comes from outside the NAT, the external address (71.120.103.159) will be returned. This is best checked by attempting to view the page in question using a HTTP proxy (to make sure the place you are viewing it from is outside the NAT).

There may be a catch with this though. In a bid to be helpful, PHP supports rewriting of the HTTP_HOST, to ensure consistency with the SERVER_NAME. This feature can be controlled in the php.ini global PHP configuration, it is called UseCanonicalName. Ensure that UseCanonicalName on does not appear in php.ini.
In response to Stephen001
I thought I looked at everything $_SERVER[] could do but I guess I didn't look very carefully because this seems to do what I want~ And the php.ini inside my WINNT folder does not have "canon" in it anywhere so that sounds like it's a good thing.