Is There any API or Plugin in PHP/Jquery, For getting local time by ip address? I have only IP Address of all users those who are registered on my site, How do I get Local Time of that particular user by only IP Address?
Asked
Active
Viewed 78 times
-1
-
please go through post `http://stackoverflow.com/questions/743505/how-to-get-time-zone-through-ip-address-in-php` – Atul Nar Nov 26 '14 at 04:58
-
Are you trying to do this on the client side or the server side? – Nov 26 '14 at 05:21
-
Suppose I have IP Address of that user like for eg. '127.121.24.24' then How do I get the Current time of that User? – user3291333 Nov 26 '14 at 06:48
1 Answers
0
This is worked for me
function get_localtime($country,$city)
{
$country = str_replace(' ', '', $country);
$city = str_replace(' ', '', $city);
$geocode_stats = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$city+$country,&sensor=false");
$output_deals = json_decode($geocode_stats);
$latLng = $output_deals->results[0]->geometry->location;
$lat = $latLng->lat;
$lng = $latLng->lng;
$google_time = file_get_contents("https://maps.googleapis.com/maps/api/timezone/json?location=$lat,$lng×tamp=1331161200&key=AIzaSyAtpji5Vk271Qu6_QFSBXwK7wpoCQLY-zQ");
$timez = json_decode($google_time);
$d = new DateTime("now", new DateTimeZone($timez->timeZoneId));
return $d->format('H : i: s');
}
//------------------------------------------------------------------------------ Getting TimeZone by the Ip Address
$location = file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key=xxxxxxxxxxx&ip=121.242.47.195&format=json');
//------------------------------------------------------------------------------
$location = json_decode($location,true);
if(is_array($location)){
echo get_timee("INDIA","MAHARASHTRA");
}else{
echo '{"statusCode":"error"}';
}
Register for a free key here: http://ipinfodb.com/register.php (no limits but queued if more than 1 request per second)
user3291333
- 1
- 4