Rev 193 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 318 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | ini_set("allow_url_fopen", 1); |
2 | ini_set("allow_url_fopen", 1); |
3 | function IPtoCoordinates($ip) |
3 | function IPtoCoordinates($ip) |
4 | { |
4 | { |
5 | // $dom = new DOMDocument(); |
5 | // $dom = new DOMDocument(); |
6 | 6 | ||
7 | $ipcheck = ip2long($ip); |
7 | $ipcheck = ip2long($ip); |
8 | if($ipcheck == -1 || $ipcheck === false) |
8 | if($ipcheck == -1 || $ipcheck === false) |
9 | trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); |
9 | trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); |
10 | else |
10 | else |
11 | - | ||
- | 11 | $key='482198dbcb57d1747babb7acebc5c02e'; |
|
12 | $uri = 'http:// |
12 | $uri = 'http://api.ipstack.com/' . $ip . '?access_key=' . $key . '&output=json&legacy=1'; |
13 | $json = file_get_contents($uri); |
13 | $json = file_get_contents($uri); |
14 | $data = json_decode($json, true); |
14 | $data = json_decode($json, true); |
15 | $location = $data['country_name']; |
15 | $location = $data['country_name']; |
16 | $longitude = $data['longitude']; |
16 | $longitude = $data['longitude']; |
17 | $latitude = $data['latitude']; |
17 | $latitude = $data['latitude']; |
18 | 18 | ||
19 | /* |
19 | /* |
20 | $uri = 'http://freegeoip.net/xml/' . $ip; |
20 | $uri = 'http://freegeoip.net/xml/' . $ip; |
21 | $dom->load($uri); |
21 | $dom->load($uri); |
22 | $location = $dom->getElementsByTagName('CountryName')->item(0)->nodeValue; |
22 | $location = $dom->getElementsByTagName('CountryName')->item(0)->nodeValue; |
23 | $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; |
23 | $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; |
24 | $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; |
24 | $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; |
25 | */ |
25 | */ |
26 | return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); |
26 | return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); |
27 | } |
27 | } |
28 | 28 | ||
29 | ?> |
29 | ?> |
30 | 30 |