孕妇过敏性鼻炎犯了怎么办:分阶处理方案
1,
'谷歌' => 2,
'搜搜' => 3,
'必应' => 4,
'雅虎' => 5,
'搜狗' => 6,
'360搜索' => 7,
'有道' => 8,
'头条' => 9,
];
// 获取蜘蛛名称
public function get_spider($string)
{
if (!$string) {
return '';
}
$string = strtolower($string);
if (stripos($string, 'baiduspider') !== false) {
return '百度';
} elseif (stripos($string, 'googlebot') !== false) {
return '谷歌';
} elseif (stripos($string, 'sosospider') !== false) {
return '搜搜';
} elseif (stripos($string, 'bingbot') !== false) {
return '必应';
} elseif (stripos($string, 'yahoo! slurp') !== false) {
return '雅虎';
} elseif (stripos($string, 'sogou') !== false) {
return '搜狗';
} elseif (stripos($string, '360spider') !== false) {
return '360搜索';
} elseif (stripos($string, 'youdaobot') !== false) {
return '有道';
} elseif (stripos($string, 'toutiao') !== false || stripos($string, 'bytespider') !== false) {
return '头条';
}
return '';
}
// 蜘蛛名称id
private function _get_spider_id($name)
{
return (int)($this->spider[$name] ?? 0);
}
// 域名白名单检测
private function _domain_check($domain)
{
if (is_file(WRITEPATH.'config/domain_spider.php')) {
$bmd = require WRITEPATH.'config/domain_spider.php';
if (in_array($domain, $bmd)) {
return 1;
}
}
$site = require WRITEPATH.'config/domain_site.php';
if (isset($site[$domain])) {
return 1;
}
return 0;
}
public function run($data)
{
$spider = $this->get_spider($_SERVER['HTTP_USER_AGENT'] ?? '');
if (!$spider) {
return '';
}
$url = dr_now_url();
$rt = $this->save_log($url, $spider, \Phpcmf\Service::C()->_is_mobile(), $data['meta_title'] ?? '', $url);
if ($rt && CI_DEBUG) {
log_message('error', '蜘蛛插件:'.$rt.'('.$url.')');
}
}
// 储存日志内容
public function save_log($url, $spider, $is_mobile, $title)
{
$spider_id = $this->_get_spider_id($spider);
if (!$spider_id) {
return '当前访客不是蜘蛛';
}
$title = trim($title);
if (!$title) {
return '网页标题为空';
}
$url = trim($url);
$arr = @parse_url($url);
$domain = $arr['host'] ?? '';
if (!$domain) {
return '域名为空';
}
if (!$this->_domain_check($domain)) {
return '域名已被过滤';
}
// 过滤无用地址
$filterKeys = [
'?debugbar',
'c=api',
'index.php?s=weixin',
'ajax',
'index.php?s=api&c=module',
'&c=html&m=',
'jQuery',
'{"code":'
];
foreach ($filterKeys as $k) {
if (strpos($url, $k) !== false) {
return;
}
}
// ===== 新增:30秒内同一个site+spider+url只记录一次,减少重复数据(核心降量)=====
$cacheKey = 'spider_log_'.SITE_ID.'_'.$spider_id.'_'.md5($url);
if (\Phpcmf\Service::L('cache')->get($cacheKey)) {
return;
}
\Phpcmf\Service::L('cache')->set($cacheKey, 1, 30);
// 移除原来的全表count+删单行逻辑,这个逻辑弊大于利
$this->table('app_spider')->insert([
'site' => SITE_ID,
'spider' => $spider_id,
'domain' => $domain,
'title' => $title,
'url' => $url,
'ip' => \Phpcmf\Service::L('input')->ip_address(),
'mobile' => $is_mobile ? 1 : 0,
'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'inputtime' => SYS_TIME,
]);
return '';
}
}
想要了解更多关于孕妇过敏性鼻炎犯了怎么办的文章欢迎访问:百科
