Ejemplo n.º 1
0
 function test_country()
 {
     $geo = new GeoIP();
     $nl = gethostbyname('nu.nl');
     // IP in the Netherlands
     $us = gethostbyname('google.com');
     // IP in the US
     $this->assertEquals($geo->getCountry($nl), array('code' => 'NL', 'country' => 'Netherlands'));
     $this->assertEquals($geo->getCountry($us), array('code' => 'US', 'country' => 'United States'));
     $this->assertTrue($geo->inCountry('NL', $nl));
     $this->assertTrue($geo->inCountry('Netherlands', $nl));
     $this->assertFalse($geo->inCountry('US', $nl));
     $this->assertFalse($geo->inCountry('NL', $us));
     $this->assertTrue($geo->inCountry('US', $us));
     $this->assertTrue($geo->inCountry('United States', $us));
 }
Ejemplo n.º 2
0
 function generateContent()
 {
     if (isset($_GET['ip'])) {
         Framework::$autoLoader->importFolder(dirname($this->paths['utils']) . '/classes');
         $geoip = new GeoIP();
         $result = $geoip->getCountry(value($_GET['ip']));
         if ($result) {
             return Alert::success('<h4>Maxmind GeoIP</h4>IP: <b>' . $_GET['ip'] . '</b> is located in <b>' . $result['country'] . '</b> (' . $result['code'] . ')');
         } else {
             return Alert::error('<h4>Maxmind GeoIP</h4>IP: <b>' . $_GET['ip'] . '</b> is not found in the country database.');
         }
     } else {
         return new Form(array('method' => 'get', 'fields' => array(new Input(array('name' => 'ip', 'placeholder' => 'IP address')), new Input(array('type' => 'submit', 'value' => 'Lookup', 'class' => 'btn btn-primary'))), 'class' => 'input-append'));
     }
 }