Ejemplo n.º 1
0
 /**
  * @return IpLoc_Locator
  */
 public function getInstance()
 {
     if (!self::$iplocDetectorInstance) {
         $dbClass = DB_CLASS;
         $db = new $dbClass(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE, DB_PERSISTANT);
         self::$iplocDetectorInstance = new IpLoc_Locator($db);
     }
     return self::$iplocDetectorInstance;
 }
Ejemplo n.º 2
0
 /**
  * 查找ip地址
  *
  * @param $ipAddress
  *
  * @return IpAddress|null
  * @throws \InvalidArgumentException
  */
 static function find($ipAddress)
 {
     if (empty($ipAddress)) {
         throw new \InvalidArgumentException('待获取的IP地址不能为空');
     }
     if (!isset(self::$_CONTAINER[$ipAddress])) {
         if (is_null(self::$instance)) {
             self::$instance = new self();
         }
         self::$_CONTAINER[$ipAddress] = self::$instance->findInner($ipAddress);
     }
     return self::$_CONTAINER[$ipAddress];
 }
Ejemplo n.º 3
0
<?php

require_once 'config.php';
$glcBlocksSource = new IpLoc_Base_Csv(GEO_LITE_CITY_BLOCKS_CSV, 2);
$glcBlocksSource->setColumnsNames(array('startIp', 2 => 'locationId'));
$glcLocationsSource = new IpLoc_Base_Csv(GEO_LITE_CITY_LOCATIONS_CSV, 2);
$glcLocationsSource->setColumnsNames(array('id', 'country', 3 => 'city', 5 => 'latitude', 6 => 'longitude'));
$updater = new IpLoc_Base_Updater(IpLocator::getInstance(), INIT_TABLES_MYSQL, $glcBlocksSource, $glcLocationsSource);
$updater->setBulkInsertLimit(DB_BULK_INSERT_LIMIT);
$updater->setDebugCallback('debug');
$updater->update();
Ejemplo n.º 4
0
<?php

require_once 'config.php';
$clientIp = empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['REMOTE_ADDR'];
?>
<form method="post">IP: <input type="text"
	value="<?php 
echo empty($_POST['ip']) ? $clientIp : $_POST['ip'];
?>
"
	name="ip" /> <input type="submit" value="Find location" /></form>
<pre>
<?php 
if (!empty($_POST['ip'])) {
    $startTime = microtime(true);
    try {
        $location = IpLocator::getInstance()->getIpLocation($_POST['ip']);
    } catch (Exception $e) {
        echo 'There is Exception in getIpLocation request. May be it\'s because you did not initialized database for IpLoc. Before using IpLoc you need to <a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/">download</a> last version of CSV base with IP locations and extract it to ' . dirname(__FILE__) . '
Then run <a href="init_base.php">init_base.php</a>';
        throw $e;
    }
    $searchTime = microtime(true) - $startTime;
    echo 'Searching time: ' . $searchTime . '<br />';
    if (!$location) {
        echo 'Location not found';
    } else {
        print_r($location);
    }
}
Ejemplo n.º 5
0
if (isset($_POST['look']) && $_POST['inp'] != '') {
    $curTime = microtime(true);
    $loc = IpLocator::getInstance();
    $res = $loc->LocateIp($_POST['inp']);
    $elp = round(microtime(true) - $curTime, 3) * 1000;
    echo '<br>';
    if ($res) {
        foreach ($res as $key => $value) {
            echo $key . ' => ' . $value . '<br>';
        }
    }
    echo '<br>';
    echo 'Elpassed time: ' . $elp . ' Us';
}
$filename = 'update/*.[zZ][iI][pP]';
if (isset($_POST['install']) && count(glob($filename)) > 0) {
    $loc = IpLocator::getInstance();
    //InstallBlocks(true for optimize best performance OR rows per indexed file, true for delete temp files);15.6965
    $loc->InstallBlocks(glob($filename)[0], true, true);
    unset($loc);
    exit;
} else {
    if (isset($_POST['install']) && count(glob($filename)) === 0) {
        echo 'Data file (update/*.ZIP) is not exist!<br>';
        echo 'Register to <a href = "http://www.ip2location.com//">www.ip2location.com</a><br>';
        echo 'Download IP Location Database CSV in Zip format and copy to update folder.';
    }
}
?>
    </body>
</html>