Jump to content

swapping IP Class for IP Variable


stan003

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.