Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP how to get local IP of system

Tags:

php

ip-address

I need to get local IP of computer like 192.*.... Is this possible with PHP?

I need IP address of system running the script, but I do not need the external IP, I need his local network card address.

like image 356
air Avatar asked Jul 10 '10 12:07

air


People also ask

How do you get the user's IP address in PHP?

Using getenv() function: To get the IP Address,we use getenv(“REMOTE_ADDR”) command. The getenv() function in PHP is used for retrieval of values of an environment variable in PHP. It is used to return the value of a specific environment variable.

How can I get IP address and store in database using PHP?

You can try this one also. $ip=$_SERVER['REMOTE_ADDR']; echo "IP address= $ip"; If your application hosted on same machine from where you are trying to request it will always return '::1', It means LocalHost. else it will return client IP Address.

How do I find my local IP address in HTML?

var ip = HttpContext. Current. Request. ServerVariables["REMOTE_ADDR"]; var ip = Request.


1 Answers

From CLI

PHP < 5.3.0

$localIP = getHostByName(php_uname('n'));

PHP >= 5.3.0

$localIP = getHostByName(getHostName());

like image 153
andras.tim Avatar answered Oct 06 '22 06:10

andras.tim