Ejemplo n.º 1
0
 /**
  * @see AbstractLocator::process()
  */
 protected function process()
 {
     $uri = ($this->ssl ? 'https://' : 'http://') . 'www.geobytes.com/IpLocator.htm?GetLocation&';
     $query = array('template' => 'php3.txt', 'IpAddress' => $this->ip);
     if ($this->email && $this->password) {
         $query = array_merge($query, array('pt_email' => $this->email, 'pt_password' => $this->password));
     }
     $response = get_meta_tags($uri . http_build_query($query));
     if ('Limit Exceeded' == $response['locationcode']) {
         throw new \Exception('Limit exceeded');
     }
     $location = new Location();
     $location->setServiceResponse($response)->setCountryCode($response['iso2'])->setCountryName($response['country'])->setCityName($response['region'])->setLatitude($response['latitude'])->setLongitude($response['longitude']);
     $this->setLocation($location);
 }
Ejemplo n.º 2
0
 /**
  * @see AbstractLocator::process()
  */
 protected function process()
 {
     $response = file_get_contents('http://geoip3.maxmind.com/f?' . http_build_query(array('l' => $this->license, 'i' => $this->ip)));
     $response = iconv('ISO-8859-1', 'UTF-8', $response);
     $values = preg_split('/,(?!\\s+)/', $response);
     array_walk($values, function (&$value) {
         $value = str_replace("\"", "", $value);
         $value = empty($value) || $value == '(null)' ? null : $value;
     });
     if (isset($values[10])) {
         $message = key_exists($values[10], $this->messages) ? $this->messages[$values[10]] : $values[5];
         throw new \Exception("Service response: '{$message}'");
     }
     $location = new Location();
     $location->setServiceResponse($response)->setCountryCode($values[0])->setCityCode($values[1])->setCityName($values[2])->setLatitude($values[4])->setLongitude($values[5]);
     $this->setLocation($location);
 }