This commit is contained in:
Krivchikov Dmitry 2016-01-15 19:22:17 +03:00
parent b7d01af3eb
commit 89b158e462
1 changed files with 27 additions and 0 deletions

27
classes/IpInfo.php Normal file
View File

@ -0,0 +1,27 @@
<?php
class IpInfo
{
static public function geo($ip)
{
App::log('ip', $ip);
$ch = curl_init("http://ipinfo.io/".$ip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$result = curl_exec($ch);
curl_close($ch);
$result = $result ? json_decode($result, true) : NULL;
$loc = array('lat' => 59.937, 'lng' => 30.349);
if (isset($result['loc'])) {
$tmp = explode(',', $result['loc']);
$loc = array('lat' => $tmp[0], 'lng' => $tmp[1]);
}
return $loc;
}
}