Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
193 | f9daq | 1 | <?php |
2 | ini_set("allow_url_fopen", 1); |
||
3 | function IPtoCoordinates($ip) |
||
4 | { |
||
5 | // $dom = new DOMDocument(); |
||
6 | |||
7 | $ipcheck = ip2long($ip); |
||
8 | if($ipcheck == -1 || $ipcheck === false) |
||
9 | trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); |
||
10 | else |
||
11 | |||
12 | $uri = 'http://freegeoip.net/json/' . $ip; |
||
13 | $json = file_get_contents($uri); |
||
14 | $data = json_decode($json, true); |
||
15 | $location = $data['country_name']; |
||
16 | $longitude = $data['longitude']; |
||
17 | $latitude = $data['latitude']; |
||
18 | |||
19 | /* |
||
20 | $uri = 'http://freegeoip.net/xml/' . $ip; |
||
21 | $dom->load($uri); |
||
22 | $location = $dom->getElementsByTagName('CountryName')->item(0)->nodeValue; |
||
23 | $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; |
||
24 | $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; |
||
25 | */ |
||
26 | return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); |
||
27 | } |
||
28 | |||
29 | ?> |