Home > Article > Backend Development > How to Retrieve the Local IP Address of Your PHP Script?
PHP Local IP Retrieval
In certain scenarios, it may be necessary to obtain the local IP address of a system running a PHP script. This address differs from the external IP, as it pertains specifically to the machine's local network card.
CLI Implementation
For PHP versions prior to 5.3.0, the following code can be used:
<code class="php">$localIP = getHostByName(php_uname('n'));</code>
For PHP versions 5.3.0 and above:
<code class="php">$localIP = getHostByName(getHostName());</code>
Note:
The above is the detailed content of How to Retrieve the Local IP Address of Your PHP Script?. For more information, please follow other related articles on the PHP Chinese website!