programming.name Posted May 7, 2010 Share Posted May 7, 2010 Hi, To get an IP address I used the following script: echo $ip = getenv("REMOTE_ADDR"); This works fine when my friends access my website, but when it comes to my main computer and the three sub computers connected to a router, it returns an internal IP address like 192.168.0.1. My web site is not local; although I run my webserver on my own, everyone in the world can access my web site. Then, I think the IP address should be external one that http://whatismyip.com shows but why does it return an internal IP address? Is there any way to fix that problem? Thanks Link to comment https://forums.phpfreaks.com/topic/201058-question-about-getting-ip-address/ Share on other sites More sharing options...
artech Posted May 7, 2010 Share Posted May 7, 2010 Do you get the same result when you get the IP using a superglobal instead of getenv()? Try: echo $ip = $_SERVER['REMOTE_ADDR']; Link to comment https://forums.phpfreaks.com/topic/201058-question-about-getting-ip-address/#findComment-1054858 Share on other sites More sharing options...
teamatomic Posted May 7, 2010 Share Posted May 7, 2010 Because the local boxes are internal, any box from outside will show the IP assigned by the ISP to the cable/dls router. If the local computers did not use an internal address it would present a problem when each box accessed the net as how would your local network know what box gets what packets? Its working as it should. You could however see if your ISP would let you buy enough IP's for each computer. If you got a business plan and paid like $80 or so a month you could probably get them for $2 monthly. If its really a big deal that you have "real" IP's for internal use. Even though you "run" your own webserver, if its within your home network its "local", no matter if you open up port 80 to outside traffic or not. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/201058-question-about-getting-ip-address/#findComment-1054888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.