PHP how to get local IP of system

air picture air · Jul 10, 2010 · Viewed 228.4k times · Source

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.

Answer

andras.tim picture andras.tim · Nov 5, 2013

From CLI

PHP < 5.3.0

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

PHP >= 5.3.0

$localIP = getHostByName(getHostName());