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

How to Get the Local IP Address in PHP?

Linda Hamilton
Release: 2024-10-24 20:47:02
Original
942 people have browsed it

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>
Copy after login

PHP Versions 5.3.0 and Later

<code class="php">$localIP = getHostByName(getHostName());</code>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template