Question:
Can PHP be used to retrieve the local IP address of a system (e.g., 192.*...)? This address should be the local network card address, not the external IP address.
Answer:
Using the Command Line Interface (CLI)
PHP Versions Prior to 5.3.0
<code class="php">$localIP = getHostByName(php_uname('n'));</code>
PHP Versions 5.3.0 and Later
<code class="php">$localIP = getHostByName(getHostName());</code>
The above is the detailed content of How to Get the Local IP Address in PHP?. For more information, please follow other related articles on the PHP Chinese website!