Finding local IP address of a machine instead of proxy ip

by rajesh 2010-01-01 16:22:36

We can not find the local intranet ip of a machine by using

echo $_SERVER['REMOTE_ADDR'];

because this will only return the proxy ip in a proxy server environment.

To find the local machines ip we have to use

echo $_SERVER['HTTP_CLIENT_IP'];

Example:

<?php

if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}

echo $ip;
?>

Tagged in:

880
like
0
dislike
0
mail
flag

You must LOGIN to add comments