Home >Backend Development >PHP Tutorial >How to Get the Local IP Address of a Computer Using PHP?
Obtaining Local IP Address in PHP
This article discusses a common question faced by developers: how to acquire the local IP address of a computer using PHP.
Question:
Can I retrieve the local IP address (e.g., 192.*....) of a computer running a PHP script, excluding the external IP?
Answer:
Yes, it is possible to obtain the local network card address with PHP.
Solution from Command-Line Interface (CLI):
For PHP versions prior to 5.3.0:
<code class="php">$localIP = getHostByName(php_uname('n'));</code>
For PHP versions 5.3.0 and above:
<code class="php">$localIP = getHostByName(getHostName());</code>
The above is the detailed content of How to Get the Local IP Address of a Computer Using PHP?. For more information, please follow other related articles on the PHP Chinese website!