예제 #1
0
 public function __destruct()
 {
     try {
         if ($this->_reader instanceof Reader) {
             $this->_reader->close();
         }
     } catch (\Exception $e) {
     }
 }
예제 #2
0
 public function testMetadata()
 {
     $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
     $this->assertEquals('GeoIP2-City', $reader->metadata()->databaseType);
     $reader->close();
 }
예제 #3
0
$referrer = isset($_GET['r']) ? $_GET['r'] : "none";
//  page from which visitor came
$origin = isset($_GET['o']) ? $_GET['o'] : "-";
//  origin of the dislike (fb only)
// connect
$logdb = new PDO("sqlite:" . $dbfolder . $dbname);
$ipReader = new Reader($dbGeofolder . '/data/GeoLite2-City.mmdb');
// check if database file exists first
// first shot, create the tables
// init
if (!file_exists($dbfolder . $dbname)) {
    $logdb->exec("CREATE TABLE hits(id INTEGER PRIMARY KEY, counter INTEGER)");
    $logdb->exec("CREATE TABLE tracker (\n        id INTEGER PRIMARY KEY AUTOINCREMENT,\n        browser TEXT default '',\n        ip varchar(15) NOT NULL default '',\n        d DATETIME NOT NULL default CURRENT_TIMESTAMP,\n        referrer TEXT NOT NULL default '' ,\n        iso_code TEXT default '',\n        country_name TEXT default '',\n        city_name TEXT default '',\n        latitude TEXT default '0',\n        longitude TEXT default '0',\n        origin TEXT default '-')");
    $logdb->exec("INSERT INTO hits(id, counter) VALUES (1, 0)");
}
// get the geo-data
$record = $ipReader->city($ip);
$iso_code = isset($record->country) ? $record->country->isoCode : '?';
$country_name = isset($record->country) ? $record->country->name : '?';
$city_name = isset($record->city) ? $record->city->name : '?';
$latitude = isset($record->location) ? $record->location->latitude : '0';
$longitude = isset($record->location) ? $record->location->longitude : '0';
// and boom ...
$logdb->exec("UPDATE hits SET counter=counter+1 WHERE id=1");
// track it!
$logdb->exec("INSERT INTO tracker(browser, ip, referrer, iso_code, country_name, city_name, latitude, longitude, origin)\n              VALUES ('{$browser}','{$ip}', '{$referrer}', '{$iso_code}', '{$country_name}', '{$city_name}', '{$latitude}', '{$longitude}', '{$origin}')\n              ");
// close connection
$logdb = null;
$ipReader->close();
// fake image
echo file_get_contents(dirname(__FILE__) . '/blank.gif');
예제 #4
0
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage is not a valid IP address
  */
 public function testInvalidAddress()
 {
     $reader = new Reader(ROOT_PDIR . 'components/geographic-codes/libs/MaxMind-DB-Reader-php/tests/data/test-data/GeoIP2-City-Test.mmdb');
     $reader->city('invalid');
     $reader->close();
 }
예제 #5
0
 public function testIsp()
 {
     $reader = new Reader('maxmind-db/test-data/GeoIP2-ISP-Test.mmdb');
     $ipAddress = '1.128.0.0';
     $record = $reader->isp($ipAddress);
     $this->assertEquals(1221, $record->autonomousSystemNumber);
     $this->assertEquals('Telstra Pty Ltd', $record->autonomousSystemOrganization);
     $this->assertEquals('Telstra Internet', $record->isp);
     $this->assertEquals('Telstra Internet', $record->organization);
     $this->assertEquals($ipAddress, $record->ipAddress);
     $reader->close();
 }