Home  >  Article  >  Backend Development  >  How to Get the Local IP Address of a Computer Using PHP?

How to Get the Local IP Address of a Computer Using PHP?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-25 06:46:29204browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn