PHP how to get local IP of system

2020-01-24 11:31发布

I need to get local IP of computer like 192.*.... Is this possible with PHP?

I need IP address of system running the script, but I do not need the external IP, I need his local network card address.

15条回答
疯言疯语
2楼-- · 2020-01-24 11:53

It is easy one. You can get the host name by this simple code.

$ip = getHostByName(getHostName());

Or you can also use $_SERVER['HTTP_HOST'] to get the hostname.

查看更多
乱世女痞
3楼-- · 2020-01-24 11:55

Try this

$localIP = gethostbyname(trim('hostname'));
查看更多
老娘就宠你
4楼-- · 2020-01-24 11:56

From CLI

PHP < 5.3.0

$localIP = getHostByName(php_uname('n'));

PHP >= 5.3.0

$localIP = getHostByName(getHostName());

查看更多
登录 后发表回答