mirror of
https://github.com/tursom/typecho-plugin-Access.git
synced 2024-12-25 20:30:32 +08:00
update ua parse file and ip parse file (#26)
* add 17monipdb.datx * Delete 17monipdb.dat * update ua parse file and ip parse file * convert CRLF to LF
This commit is contained in:
parent
6d9b80c317
commit
64594b7640
@ -1,28 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
本代码仅用于 DATX 格式,请注意及时更新 IP 数据库版本
|
||||
Code for PHP 5.3+ only!
|
||||
*/
|
||||
if (!defined('__ACCESS_PLUGIN_ROOT__')) {
|
||||
throw new Exception('Boostrap file not found');
|
||||
}
|
||||
|
||||
class Access_Ip
|
||||
{
|
||||
private static $ip = null;
|
||||
private static $ip = NULL;
|
||||
|
||||
private static $fp = null;
|
||||
private static $offset = null;
|
||||
private static $index = null;
|
||||
private static $fp = NULL;
|
||||
private static $offset = NULL;
|
||||
private static $index = NULL;
|
||||
|
||||
private static $cached = array();
|
||||
|
||||
public static function find($ip)
|
||||
{
|
||||
if (empty($ip) === true) {
|
||||
if (empty($ip) === TRUE)
|
||||
{
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
$nip = gethostbyname($ip);
|
||||
$nip = gethostbyname($ip);
|
||||
$ipdot = explode('.', $nip);
|
||||
|
||||
if ($ipdot[0] < 0 || $ipdot[0] > 255 || count($ipdot) !== 4) {
|
||||
if ($ipdot[0] < 0 || $ipdot[0] > 255 || count($ipdot) !== 4)
|
||||
{
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
@ -30,31 +36,35 @@ class Access_Ip
|
||||
return self::$cached[$nip];
|
||||
}
|
||||
|
||||
if (self::$fp === null) {
|
||||
if (self::$fp === NULL)
|
||||
{
|
||||
self::init();
|
||||
}
|
||||
|
||||
$nip2 = pack('N', ip2long($nip));
|
||||
|
||||
$tmp_offset = (int) $ipdot[0] * 4;
|
||||
$start = unpack('Vlen', self::$index[$tmp_offset] . self::$index[$tmp_offset + 1] . self::$index[$tmp_offset + 2] . self::$index[$tmp_offset + 3]);
|
||||
$tmp_offset = ((int)$ipdot[0] * 256 + (int)$ipdot[1]) * 4;
|
||||
$start = unpack('Vlen', self::$index[$tmp_offset] . self::$index[$tmp_offset + 1] . self::$index[$tmp_offset + 2] . self::$index[$tmp_offset + 3]);
|
||||
|
||||
$index_offset = $index_length = null;
|
||||
$max_comp_len = self::$offset['len'] - 1024 - 4;
|
||||
for ($start = $start['len'] * 8 + 1024; $start < $max_comp_len; $start += 8) {
|
||||
if (self::$index{$start} . self::$index{$start + 1} . self::$index{$start + 2} . self::$index{$start + 3} >= $nip2) {
|
||||
$index_offset = $index_length = NULL;
|
||||
$max_comp_len = self::$offset['len'] - 262144 - 4;
|
||||
for ($start = $start['len'] * 9 + 262144; $start < $max_comp_len; $start += 9)
|
||||
{
|
||||
if (self::$index{$start} . self::$index{$start + 1} . self::$index{$start + 2} . self::$index{$start + 3} >= $nip2)
|
||||
{
|
||||
$index_offset = unpack('Vlen', self::$index{$start + 4} . self::$index{$start + 5} . self::$index{$start + 6} . "\x0");
|
||||
$index_length = unpack('Clen', self::$index{$start + 7});
|
||||
$index_length = unpack('nlen', self::$index{$start + 7} . self::$index{$start + 8});
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($index_offset === null) {
|
||||
if ($index_offset === NULL)
|
||||
{
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
fseek(self::$fp, self::$offset['len'] + $index_offset['len'] - 1024);
|
||||
fseek(self::$fp, self::$offset['len'] + $index_offset['len'] - 262144);
|
||||
|
||||
self::$cached[$nip] = explode("\t", fread(self::$fp, $index_length['len']));
|
||||
|
||||
@ -63,17 +73,20 @@ class Access_Ip
|
||||
|
||||
private static function init()
|
||||
{
|
||||
if (self::$fp === null) {
|
||||
if (self::$fp === NULL)
|
||||
{
|
||||
self::$ip = new self();
|
||||
|
||||
self::$fp = fopen(__ACCESS_PLUGIN_ROOT__ . '/lib/17monipdb.dat', 'rb');
|
||||
if (self::$fp === false) {
|
||||
throw new Exception('Invalid 17monipdb.dat file!');
|
||||
self::$fp = fopen(__ACCESS_PLUGIN_ROOT__ . '/lib/17monipdb.datx', 'rb');
|
||||
if (self::$fp === FALSE)
|
||||
{
|
||||
throw new Exception('Invalid 17monipdb.datx file!');
|
||||
}
|
||||
|
||||
self::$offset = unpack('Nlen', fread(self::$fp, 4));
|
||||
if (self::$offset['len'] < 4) {
|
||||
throw new Exception('Invalid 17monipdb.dat file!');
|
||||
if (self::$offset['len'] < 4)
|
||||
{
|
||||
throw new Exception('Invalid 17monipdb.datx file!');
|
||||
}
|
||||
|
||||
self::$index = fread(self::$fp, self::$offset['len'] - 4);
|
||||
@ -82,8 +95,13 @@ class Access_Ip
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if (self::$fp !== null) {
|
||||
if (self::$fp !== NULL)
|
||||
{
|
||||
fclose(self::$fp);
|
||||
|
||||
self::$fp = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
633
Access_UA.php
633
Access_UA.php
@ -1,323 +1,350 @@
|
||||
<?php
|
||||
if (!defined('__ACCESS_PLUGIN_ROOT__')) {
|
||||
throw new Exception('Boostrap file not found');
|
||||
throw new Exception('Boostrap file not found');
|
||||
}
|
||||
|
||||
class Access_UA
|
||||
{
|
||||
private static $robots = array(
|
||||
'TencentTraveler',
|
||||
'Baiduspider',
|
||||
'BaiduGame',
|
||||
'Googlebot',
|
||||
'msnbot',
|
||||
'Sosospider+',
|
||||
'Sogou web spider',
|
||||
'ia_archiver',
|
||||
'Yahoo! Slurp',
|
||||
'YoudaoBot',
|
||||
'Yahoo Slurp',
|
||||
'MSNBot',
|
||||
'Java (Often spam bot)',
|
||||
'BaiDuSpider',
|
||||
'Voila',
|
||||
'Yandex bot',
|
||||
'BSpider',
|
||||
'twiceler',
|
||||
'Sogou Spider',
|
||||
'Speedy Spider',
|
||||
'Google AdSense',
|
||||
'Heritrix',
|
||||
'Python-urllib',
|
||||
'Alexa (IA Archiver)',
|
||||
'Ask',
|
||||
'Exabot',
|
||||
'Custo',
|
||||
'OutfoxBot/YodaoBot',
|
||||
'yacy',
|
||||
'SurveyBot',
|
||||
'legs',
|
||||
'lwp-trivial',
|
||||
'Nutch',
|
||||
'StackRambler',
|
||||
'The web archive (IA Archiver)',
|
||||
'Perl tool',
|
||||
'MJ12bot',
|
||||
'Netcraft',
|
||||
'MSIECrawler',
|
||||
'WGet tools',
|
||||
'larbin',
|
||||
'Fish search',
|
||||
'crawler',
|
||||
'bingbot',
|
||||
'YisouSpider',
|
||||
);
|
||||
private $ua;
|
||||
private $ual;
|
||||
|
||||
private $osID = null;
|
||||
private $osName = null;
|
||||
private $osVersion = null;
|
||||
|
||||
private $robotID = null;
|
||||
private $robotName = null;
|
||||
private $robotVersion = null;
|
||||
|
||||
private $browserID = null;
|
||||
private $browserName = null;
|
||||
private $browserVersion = null;
|
||||
class Access_UA {
|
||||
private static $robots = array(
|
||||
'DuckDuckGo-Favicons-Bot', // DuckDuckGo
|
||||
'gce-spider', // 谷歌GCE
|
||||
'YisouSpider', // 宜搜
|
||||
'YandexBot', // Yandex
|
||||
'UptimeRobot', // Uptime在线率检测
|
||||
'TencentTraveler',
|
||||
'Baiduspider',
|
||||
'BaiduGame',
|
||||
'Googlebot',
|
||||
'msnbot',
|
||||
'Sosospider+',
|
||||
'Sogou web spider',
|
||||
'ia_archiver',
|
||||
'Yahoo! Slurp',
|
||||
'YoudaoBot',
|
||||
'Yahoo Slurp',
|
||||
'MSNBot',
|
||||
'Java (Often spam bot)',
|
||||
'BaiDuSpider',
|
||||
'Voila',
|
||||
'Yandex bot',
|
||||
'BSpider',
|
||||
'twiceler',
|
||||
'Sogou Spider',
|
||||
'Speedy Spider',
|
||||
'Google AdSense',
|
||||
'Heritrix',
|
||||
'Python-urllib',
|
||||
'Alexa (IA Archiver)',
|
||||
'Ask',
|
||||
'Exabot',
|
||||
'Custo',
|
||||
'OutfoxBot/YodaoBot',
|
||||
'yacy',
|
||||
'SurveyBot',
|
||||
'legs',
|
||||
'lwp-trivial',
|
||||
'Nutch',
|
||||
'StackRambler',
|
||||
'The web archive (IA Archiver)',
|
||||
'Perl tool',
|
||||
'MJ12bot',
|
||||
'Netcraft',
|
||||
'MSIECrawler',
|
||||
'WGet tools',
|
||||
'larbin',
|
||||
'Fish search',
|
||||
'crawler',
|
||||
'bingbot',
|
||||
);
|
||||
|
||||
function __construct($ua) {
|
||||
$this->ua = $ua;
|
||||
$this->ual = $this->filter($ua);
|
||||
}
|
||||
private $ua;
|
||||
private $ual;
|
||||
|
||||
private $osID = null;
|
||||
private $osName = null;
|
||||
private $osVersion = null;
|
||||
|
||||
private $robotID = null;
|
||||
private $robotName = null;
|
||||
private $robotVersion = null;
|
||||
|
||||
private $browserID = null;
|
||||
private $browserName = null;
|
||||
private $browserVersion = null;
|
||||
|
||||
public static function filter($str)
|
||||
{
|
||||
return self::removeSpace(strtolower($str));
|
||||
}
|
||||
function __construct($ua) {
|
||||
$this->ua = $ua;
|
||||
$this->ual = $this->filter($ua);
|
||||
}
|
||||
|
||||
protected static function removeSpace($str)
|
||||
{
|
||||
return preg_replace('/\s+/', '', $str);
|
||||
}
|
||||
public static function filter($str) {
|
||||
return self::removeSpace(strtolower($str));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整UA信息
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getUA() {
|
||||
return $this->ua;
|
||||
}
|
||||
protected static function removeSpace($str) {
|
||||
return preg_replace('/\s+/', '', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否是爬虫
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isRobot()
|
||||
{
|
||||
if ($this->robotID === null) {
|
||||
if (!empty($this->ua)) {
|
||||
if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /v]*([0-9.]*)#i', $this->ua, $matches)) {
|
||||
$this->robotID = $this->robotName = $matches[1];
|
||||
$this->robotVersion = $matches[2];
|
||||
}
|
||||
foreach (self::$robots as $val) {
|
||||
if (strpos($this->ual, $this->filter($val)) !== false) {
|
||||
$this->robotID = $this->robotName = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->robotID == null) $this->robotID = '';
|
||||
if ($this->robotName == null) $this->robotName = '';
|
||||
if ($this->robotVersion == null) $this->robotVersion = '';
|
||||
}
|
||||
return $this->robotID !== '';
|
||||
}
|
||||
/**
|
||||
* 获取完整UA信息
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getUA() {
|
||||
return $this->ua;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取爬虫ID
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getRobotID()
|
||||
{
|
||||
return $this->isRobot() ? $this->robotID : '';
|
||||
}
|
||||
/**
|
||||
* 获取是否是爬虫
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isRobot() {
|
||||
if ($this->robotID === null) {
|
||||
if (!empty($this->ua)) {
|
||||
if (preg_match('#([a-zA-Z0-9]+\s*(?:bot|spider))[ /v]*([0-9.]*)#i', $this->ua, $matches)) {
|
||||
$this->robotID = $this->robotName = $matches[1];
|
||||
$this->robotVersion = $matches[2];
|
||||
}
|
||||
foreach (self::$robots as $val) {
|
||||
if (strpos($this->ual, $this->filter($val)) !== false) {
|
||||
$this->robotID = $this->robotName = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->robotID == null) $this->robotID = '';
|
||||
if ($this->robotName == null) $this->robotName = '';
|
||||
if ($this->robotVersion == null) $this->robotVersion = '';
|
||||
}
|
||||
return $this->robotID !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取爬虫版本
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getRobotVersion()
|
||||
{
|
||||
return $this->isRobot() ? $this->robotVersion : '';
|
||||
}
|
||||
/**
|
||||
* 获取爬虫ID
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getRobotID() {
|
||||
return $this->isRobot() ? $this->robotID : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析操作系统信息
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function parseOS()
|
||||
{
|
||||
if ($this->osID === null) {
|
||||
if (preg_match('/Windows NT 6.0/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = 'Vista';
|
||||
} elseif (preg_match('/Windows NT 6.1/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '7';
|
||||
} elseif (preg_match('/Windows NT 6.2/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '8';
|
||||
} elseif (preg_match('/Windows NT 6.3/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '8.1';
|
||||
} elseif (preg_match('/Windows NT 10.0/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '10';
|
||||
} elseif (preg_match('/Windows NT 5.1/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = 'XP';
|
||||
} elseif (preg_match('/Windows NT 5.2/i', $this->ua) && preg_match('/Win64/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = 'XP (64 bit)';
|
||||
} elseif (preg_match('/Android ([0-9.]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Android';
|
||||
$this->osVersion = $matches[1];
|
||||
} elseif (preg_match('/iPhone OS ([_0-9]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'iPhone OS';
|
||||
$this->osVersion = $matches[1];
|
||||
} elseif (preg_match('/Ubuntu/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Ubuntu';
|
||||
$this->osVersion = '';
|
||||
} elseif (preg_match('/Mac OS X ([0-9_]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Mac OS X';
|
||||
$this->osVersion = $matches[1];
|
||||
} elseif (preg_match('/Linux/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Linux';
|
||||
$this->osVersion = '';
|
||||
} else {
|
||||
$this->osID = '';
|
||||
$this->osName = '';
|
||||
$this->osVersion = '';
|
||||
}
|
||||
}
|
||||
return $this->osID !== '' || $this->osName !== '';
|
||||
}
|
||||
/**
|
||||
* 获取爬虫版本
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getRobotVersion() {
|
||||
return $this->isRobot() ? $this->robotVersion : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统ID
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOSID() {
|
||||
return $this->parseOS() ? $this->osID : '';
|
||||
}
|
||||
/**
|
||||
* 解析操作系统信息
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function parseOS() {
|
||||
if ($this->osID === null) {
|
||||
if (preg_match('/Windows NT 6.0/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = 'Vista';
|
||||
} elseif (preg_match('/Windows NT 6.1/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '7';
|
||||
} elseif (preg_match('/Windows NT 6.2/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '8';
|
||||
} elseif (preg_match('/Windows NT 6.3/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '8.1';
|
||||
} elseif (preg_match('/Windows NT 10.0/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '10';
|
||||
} elseif (preg_match('/Windows NT 5.0/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = '2000';
|
||||
} elseif (preg_match('/Windows NT 5.1/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
$this->osVersion = 'XP';
|
||||
} elseif (preg_match('/Windows NT 5.2/i', $this->ua)) {
|
||||
$this->osID = $this->osName = 'Windows';
|
||||
if (preg_match('/Win64/i', $this->ua)) {
|
||||
$this->osVersion = 'XP (64 bit)';
|
||||
} else {
|
||||
$this->osVersion = '2003';
|
||||
}
|
||||
} elseif (preg_match('/Android ([0-9.]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Android';
|
||||
$this->osVersion = $matches[1];
|
||||
} elseif (preg_match('/iPhone OS ([_0-9]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'iPhone OS';
|
||||
$this->osVersion = str_replace('_', '.', $matches[1]);
|
||||
} elseif (preg_match('/iPad; CPU OS ([_0-9]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'iPad OS';
|
||||
$this->osVersion = str_replace('_', '.', $matches[1]);
|
||||
} elseif (preg_match('/Mac OS X ([0-9_]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Mac OS X';
|
||||
$this->osVersion = str_replace('_', '.', $matches[1]);
|
||||
} elseif (preg_match('/Linux/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Linux';
|
||||
$this->osVersion = '';
|
||||
} elseif (preg_match('/Ubuntu/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Ubuntu';
|
||||
$this->osVersion = '';
|
||||
} elseif (preg_match('/CrOS i686 ([a-zA-Z0-9.]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Chrome OS';
|
||||
$this->osVersion = 'i686 ' . substr($matches[1], 0, 4);
|
||||
} elseif (preg_match('/CrOS x86_64 ([a-zA-Z0-9.]+)/i', $this->ua, $matches)) {
|
||||
$this->osID = $this->osName = 'Chrome OS';
|
||||
$this->osVersion = 'x86_64 ' . substr($matches[1], 0, 4);
|
||||
} else {
|
||||
$this->osID = '';
|
||||
$this->osName = '';
|
||||
$this->osVersion = '';
|
||||
}
|
||||
}
|
||||
return $this->osID !== '' || $this->osName !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统名字
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOSName() {
|
||||
return $this->parseOS() ? $this->osName : '';
|
||||
}
|
||||
/**
|
||||
* 获取操作系统ID
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOSID() {
|
||||
return $this->parseOS() ? $this->osID : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统版本号
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOSVersion() {
|
||||
return $this->parseOS() ? $this->osVersion : '';
|
||||
}
|
||||
/**
|
||||
* 获取操作系统名字
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOSName() {
|
||||
return $this->parseOS() ? $this->osName : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析浏览器信息
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function parseBrowser() {
|
||||
if ($this->browserName === null) {
|
||||
if (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Camino';
|
||||
$this->browserVersion = $matches[2];
|
||||
} elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'SE 2';
|
||||
$this->browserName = '搜狗浏览器 2';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = '360';
|
||||
$this->browserName = '360浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Maxthon';
|
||||
$this->browserVersion = $matches[2];
|
||||
} elseif (preg_match('#Edge/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Edge';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Chrome';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = '小米浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Safari';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#opera mini#i', $this->ua)) {
|
||||
preg_match('#Opera/([a-zA-Z0-9.]+)#i', $this->ua, $matches);
|
||||
$this->browserID = $this->browserName = 'Opera Mini';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Opera';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'TencentTraveler';
|
||||
$this->browserName = '腾讯TT浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'UCWEB';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Internet Explorer';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Trident#', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Internet Explorer';
|
||||
$this->browserVersion = '11';
|
||||
} elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Firefox';
|
||||
$this->browserVersion = $matches[2];
|
||||
} else {
|
||||
$this->browserID = '';
|
||||
$this->browserName = '';
|
||||
$this->browserVersion = '';
|
||||
}
|
||||
}
|
||||
return $this->browserID !== '' || $this->browserName !== '';
|
||||
}
|
||||
/**
|
||||
* 获取操作系统版本号
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getOSVersion() {
|
||||
return $this->parseOS() ? $this->osVersion : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浏览器ID
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserID() {
|
||||
return $this->parseBrowser() ? $this->browserID : '';
|
||||
}
|
||||
/**
|
||||
* 解析浏览器信息
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function parseBrowser() {
|
||||
if ($this->browserName === null) {
|
||||
if (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'Camino';
|
||||
$this->browserName = 'Camino';
|
||||
$this->browserVersion = $matches[2];
|
||||
} elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'SE 2';
|
||||
$this->browserName = '搜狗浏览器 2';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = '360';
|
||||
$this->browserName = '360浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Maxthon';
|
||||
$this->browserVersion = $matches[2];
|
||||
} elseif (preg_match('#Edge/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Edge';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Chrome';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = '小米浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Safari';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#opera mini#i', $this->ua)) {
|
||||
preg_match('#Opera/([a-zA-Z0-9.]+)#i', $this->ua, $matches);
|
||||
$this->browserID = $this->browserName = 'Opera Mini';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Opera';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'TencentTraveler';
|
||||
$this->browserName = '腾讯TT浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#QQ/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'QQ';
|
||||
$this->browserName = '手机QQ';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'UCWEB';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#UCBrowser/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'UCBrowser';
|
||||
$this->browserName = 'UC浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Quark/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = 'Quark';
|
||||
$this->browserName = 'Quark浏览器';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Internet Explorer';
|
||||
$this->browserVersion = $matches[1];
|
||||
} elseif (preg_match('#Trident#', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Internet Explorer';
|
||||
$this->browserVersion = '11';
|
||||
} elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $this->ua, $matches)) {
|
||||
$this->browserID = $this->browserName = 'Firefox';
|
||||
$this->browserVersion = $matches[2];
|
||||
} else {
|
||||
$this->browserID = '';
|
||||
$this->browserName = '';
|
||||
$this->browserVersion = '';
|
||||
}
|
||||
}
|
||||
return $this->browserID !== '' || $this->browserName !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浏览器名字
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserName() {
|
||||
return $this->parseBrowser() ? $this->browserName : '';
|
||||
}
|
||||
/**
|
||||
* 获取浏览器ID
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserID() {
|
||||
return $this->parseBrowser() ? $this->browserID : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浏览器版本号
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserVersion() {
|
||||
return $this->parseBrowser() ? $this->browserVersion : '';
|
||||
}
|
||||
/**
|
||||
* 获取浏览器名字
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserName() {
|
||||
return $this->parseBrowser() ? $this->browserName : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浏览器版本号
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBrowserVersion() {
|
||||
return $this->parseBrowser() ? $this->browserVersion : '';
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
BIN
lib/17monipdb.datx
Normal file
BIN
lib/17monipdb.datx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user