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

Patricia Arquette
Release: 2024-10-25 06:46:29
Original
116 people have browsed it

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

For PHP versions 5.3.0 and above:

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!