'localhost', 'database' => 'schaufelberger', 'user' => 'gerd', 'password' => 'gerd123' ); WBParam::set('wb/cache/use', 0); class BrowserDetector { /** * * @var WBInfo_Browser */ private $bi; /** * HTML mode */ private $html = false; /** * * @var WBDatasource_Table */ private $table; private $bots = array( 'Acoon v4.10.1 (www.acoon.de)' => 'acoon', 'DLE_Spider.exe' => 'DLS', 'MLBot (www.metadatalabs.com/mlbot)' => 'mlbot', 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt; DTS Agent' => 'DTS Agent', 'Mozilla/5.0 (compatible; AhrefsBot/2.0; +http://ahrefs.com/robot/)' => 'ahrefs bot', 'Mozilla/5.0 (compatible; discobot/2.0; +http://discoveryengine.com/discobot.html)' => 'dicobot', 'Mozilla/5.0 (compatible; IPTCBOT;' => 'IPTCBOT', 'Mozilla/5.0 (compatible; Sitedomain-Bot 1.0; Headers only; +http://www.sitedomain.de/sitedomain-bot/)' => 'Sitedomain-Bot', 'Mozilla/5.0 (compatible; SWEBot/1.0; +http://swebot.net)' => 'SWEBot', 'Pixray-Seeker/1.1 (Pixray-Seeker; http://www.pixray.com/pixraybot; crawler@pixray.com)' => 'Pixray', 'ssearch_bot (sSearch Crawler; http://www.semantissimo.de)' => 'Semantissimo Bot', ); public function __construct() { $this->bi = WBClass::create('WBInfo_Browser'); $this->table = WBClass::create('WBDatasource_Table_Statistic'); WBClass::load('WBClock'); } public function configDb($parameter = array()) { if (empty($parameter)) { return; } $this->table = WBClass::create('WBDatasource_Table_Statistic', $parameter); } public function detect($useragent = null) { $now = WBClock::now(); $this->bi->detect($useragent); $tD = WBClock::stop($now); $name = $this->bi->getName(); if ('Default Browser' == $name) { $name = sprintf('__%s__' , $name); } $out = array(); $out[] = sprintf('***User Agent: %s***', $this->bi->getUserAgent()); $out[] = sprintf(' Time: %s', $tD); $out[] = sprintf(' Crawler: %d', $this->bi->isCrawler()); $out[] = sprintf(' Plattform: %s ', $this->bi->getPlatform()); $out[] = sprintf(' Name: %s ', $name); $out[] = sprintf(' Version: %s (major: %d, minor: %d) ' , $this->bi->getVersion() , $this->bi->getVersion(WBInfo_Browser::VER_TYPE_MAJOR) , $this->bi->getVersion(WBInfo_Browser::VER_TYPE_MINOR) ); foreach ($out as $o) { if ($this->html) { // use tags } echo $o . "\n"; } flush(); } public function checkSessionLog() { $now = WBClock::now(); $options = array( 'groupby' => array( 'field' => 'useragent' ) ); $list = $this->table->get('sessionview', null, null, array(), $options); $clause = array(); $clause[] = array( 'field' => 'useragent', 'value' => 'x' ); foreach ($list as $l) { if ('undefined' == $l['useragent']) { continue; } if (isset($this->bots[$l['useragent']])) { $save = array( 'browser' => $this->bots[$l['useragent']], 'hint' => 'spider' ); $clause[0]['value'] = $l['useragent']; $this->table->save('sessionview', null, $save, $clause); continue; } $this->detect($l['useragent']); $save = array( 'browser' => $this->bi->getName(), 'platform' => $this->bi->getPlatform(), 'majorversion' => $this->bi->getVersion(WBInfo_Browser::VER_TYPE_MAJOR), 'minorversion' => $this->bi->getVersion(WBInfo_Browser::VER_TYPE_MINOR) ); if ($this->bi->isCrawler()) { $save['hint'] = 'spider'; } $clause[0]['value'] = $l['useragent']; $this->table->save('sessionview', null, $save, $clause); } echo sprintf(' updated %d records used %sms', count($list), WBClock::stop($now)) . "\n"; } } $t = new BrowserDetector(); $t->configDb($db); //$t->detect('blah blah browser does not exist'); $t->detect('Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'); $t->detect(); //$t->detect('Pixray-Seeker/1.1 (Pixray-Seeker; http://www.pixray.com/pixraybot; crawler@pixray.com)'); $t->checkSessionLog();