Tuesday, August 6, 2013

Get Current location address(country,city) from IP address using API

<?php
// Get current IP address using API
$ip_address = file_get_contents("http://ip6.me/");
// Get IP Address value using this function
$ip_data = explode(".",$ip_address);
$first_ip_element = substr(preg_replace('/[^0-9]/','',$ip_data[0]),-3);
// Get Current location address with Ip address
$f_get = file_get_contents("http://api.hostip.info/get_html.php?ip=".$first_ip_element.'.'.$ip_data[1].'.'.$ip_data[2].'.'.$ip_data[3]);
echo $f_get;
?> 

No comments:

Post a Comment