コード例 #1
0
ファイル: MaxmindDriver.php プロジェクト: josezenem/geoip
 /**
  * Get the raw GeoIP info using Maxmind.
  * 
  * @param  string $ip
  * 
  * @return mixed
  */
 public function getRaw($ip)
 {
     try {
         return $this->maxmind->city($ip);
     } catch (AddressNotFoundException $e) {
         // ignore
     }
     return [];
 }
コード例 #2
0
 public function getIsoCodeFromIpAddress($ipAddress)
 {
     if ($this->userId == '') {
         return null;
     }
     if ($ipAddress == '127.0.0.1') {
         return null;
     }
     // @codeCoverageIgnoreStart
     $client = new Client($this->userId, $this->licenseKey);
     $model = $client->country($ipAddress);
     $isoCode = $model->country->isoCode;
     return $isoCode;
     // @codeCoverageIgnoreEnd
 }
コード例 #3
0
ファイル: precision.php プロジェクト: ryan2407/Vision
 public function city($ip)
 {
     $method = get_option('geoip-detect-precision_api_type', 'city');
     $ret = null;
     $callback = array($this, $method);
     if (!is_callable($callback)) {
         throw new \RuntimeException('Precision API: Unsupported method ' . $method);
     }
     if ($method == 'city') {
         $ret = parent::city($ip);
     } else {
         $ret = call_user_func_array($callback, array($ip));
     }
     /* Web-API-specific exceptions:
     			} catch (AuthenticationException $e) {
     			} catch (OutOfQueriesException $e) {
     			}
     			*/
     if ($ret) {
         $credits = $ret->maxmind->queriesRemaining;
         // This seems to be approximate.
         update_option('geoip-detect-precision-remaining_credits', $credits);
     }
     return $ret;
 }
コード例 #4
0
ファイル: MaxmindVisitor.php プロジェクト: cubex/framework
 public function __destruct()
 {
     try {
         if ($this->_reader instanceof Reader) {
             $this->_reader->close();
         }
     } catch (\Exception $e) {
     }
 }
コード例 #5
0
ファイル: geoip.php プロジェクト: AndyJS/hm-time
function hm_time_geoip_lookup($hostname = null)
{
    if (empty($hostname)) {
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $hostname = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            //to check ip is pass from proxy
            $hostname = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $hostname = $_SERVER['REMOTE_ADDR'];
        }
    }
    $maxmind_user_id = hm_time_options('geoip_user_id', 'string');
    $maxmind_user_id = (int) $maxmind_user_id;
    $maxmind_license_key = hm_time_options('geoip_license_key');
    $client = new Client($maxmind_user_id, $maxmind_license_key);
    try {
        $record = $client->omni($hostname);
    } catch (GeoIp2\Exception\AddressNotFoundException $e) {
        return false;
    }
    return $record;
}
コード例 #6
0
 public function testParams()
 {
     $plugin = new MockPlugin();
     $plugin->addResponse($this->getResponse('1.2.3.4'));
     $guzzleClient = new GuzzleClient();
     $guzzleClient->addSubscriber($plugin);
     $client = new Client(42, 'abcdef123456', array('en'), 'geoip.maxmind.com', $guzzleClient);
     $client->country('1.2.3.4');
     $all_requests = $plugin->getReceivedRequests();
     $request = $all_requests[0];
     $this->assertEquals('https://geoip.maxmind.com/geoip/v2.1/country/1.2.3.4', $request->getUrl(), 'got expected URI for Country request');
     $this->assertEquals('GET', $request->getMethod(), 'request is a GET');
     $this->assertEquals('application/json', $request->getHeader('Accept'), 'request sets Accept header to application/json');
     $this->assertStringMatchesFormat('GeoIP2 PHP API (Guzzle%s)', $request->getHeader('User-Agent') . '', 'request sets Accept header to application/json');
 }
コード例 #7
0
 /**
  * @group external-http
  * @expectedException \GeoIp2\Exception\AuthenticationException
  */
 function testMaxmindApiPasswordWrong2()
 {
     $client = new Client('', '');
     $client->city('8.8.8.8');
 }