Home  >  Article  >  Backend Development  >  How to Get the Local IP Address in PHP?

How to Get the Local IP Address in PHP?

Linda Hamilton
Linda HamiltonOriginal
2024-10-24 20:47:02838browse

How to Get the Local IP Address in PHP?

How to Obtain Local IP Address in PHP

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!

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