Finding local IP address of a machine instead of proxy ip
by rajesh[ Edit ] 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;
?>