Thursday, April 30, 2009

Get Geo Location using User IP Address

function get_ip_location($ip, $format="xml") {

/* Set allowed output formats */
$formats_allowed = array("json", "xml", "raw");

/* IP location query url */
$query_url = "http://iplocationtools.com/ip_query.php?ip=";

/* Male sure that the format is one of json, xml, raw.
Or else default to xml */
if(!in_array($format, $formats_allowed)) {
$format = "xml";
}

$query_url = $query_url . "{$ip}&output={$format}";

/* Init CURL and its options*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $query_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);

/* Execute CURL and get the response */
return curl_exec($ch);

}

print_r(get_ip_location("95.12.220.161"));

more info.. http://evergreenphp.blogspot.com

1 comment:

VENKAT said...

In the above article i read the codings for the getting the geo location using the Ip-Address.It is not only by I had recently in browsing the opened a website www.ip-details.comIt shows the Ip-Address details country,city,location using maps,longitude,latitude,speed test also.