Subversion Repositories f9daq

Rev

Rev 193 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.           $key='482198dbcb57d1747babb7acebc5c02e';
  12.           $uri = 'http://api.ipstack.com/' . $ip . '?access_key=' . $key . '&output=json&legacy=1';
  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. ?>
  30.