HI,
I have some code that obtains the ip address of the visitor and then looks up their ip address, a copy of the code is below:
function getRealIpAddr()
{
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'];
}
return $ip;
}
function IPtoLatLng($ip)
{
$latlngValue=array();
$dom = new DOMDocument();
$ipcheck = ip2long($ip);
if($ipcheck == -1 || $ipcheck === false){
echo "ERROR: INVALID IP";
exit;
}
else
$uri = "http://api.hostip.info/?ip=$ip&position=true";
No what i want to do is swap the GetRealIp for a php variable, however when i write the code like this:
$ip = "$ip";
function IPtoLatLng($ip)
{
$latlngValue=array();
$dom = new DOMDocument();
$ipcheck = ip2long($ip);
if($ipcheck == -1 || $ipcheck === false){
echo "ERROR: INVALID IP";
exit;
}
else
$uri = "http://api.hostip.info/?ip=$ip&position=true";
$dom->load($uri);
$name=$dom->getElementsByTagNameNS('http://www.opengis.net/gml','name')->item(1)->nodeValue;
$coordinates=$dom->getElementsByTagNameNS('http://www.opengis.net/gml','coordinates')->item(0)->nodeValue;
$temp=explode(",",$coordinates);
$latlngValue['LNG']=$temp[0];
$latlngValue['LAT']=$temp[1];
$latlngValue['NAME']=$name;
return $latlngValue;
}
It returns Invalid IP,
however no matter what i try i get the same response over and over again.
Any suggestions would be appreciated.
Thanks
Stan