How do I get the inner IP address in my webpage? Can be any language for designing a website (javascript,php,etc.). What I need to do actually, is to make a local web server, and to let the clients in the same wifi network to connect via its shown IP address(192.168.X.X) on a webpage. But I always get 127.0.0.1 in php instead of 192.168.X.X, any ideas?
Asked
Active
Viewed 8,149 times
4
-
3Check http://stackoverflow.com/questions/3219178/php-how-to-get-local-ip-of-system which contains the same question. – Jensen Mar 02 '13 at 11:11
-
1When you run your page on your localhost you always get your localhost IP: 127.0.0.1 If you upload it to another server you can see your WAN IP – zkanoca Mar 02 '13 at 11:12
3 Answers
6
I solved by the following code, getting the wireless local IP address(192.168.X.X):
$myIP = gethostbyname(trim(`hostname`));

Jeffrey Neo
- 3,693
- 2
- 26
- 30
0
// PHP < 5.3.0
$Local_IP = @gethostbyname(php_uname('n'));
// PHP >= 5.3.0
$Local_IP = @gethostbyname(getHostName());

AbdulRahman AlShamiri
- 193
- 1
- 4
-1
You just have to read it in
$ip = $_SERVER['SERVER_ADDR'];
If you want to know all data available in $_SERVER use:
print("<pre>\n");
print_r($_SERVER);
print("\n</pre>\n");
$_SERVER contains lots of useful informations. You may also want to check:
$_SERVER['LOCAL_ADDR']

Jean
- 7,623
- 6
- 43
- 58
-
1the server is using localhost, so it won't get the expected ip by using **$_SERVER**, it return 127.0.0.1 to me. thanks anyway. – Jeffrey Neo Mar 02 '13 at 15:06