diff --git a/app/common.php b/app/common.php index b6d9049..8ccedb9 100644 --- a/app/common.php +++ b/app/common.php @@ -292,6 +292,20 @@ function get_login_user($key = "") return ''; } } + +/** + * 判断访客是否是蜘蛛 + */ +function isRobot($except = '') { + $ua = strtolower ( $_SERVER ['HTTP_USER_AGENT'] ); + $botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla|AhrefsBot)/i"; + $except ? $botchar = str_replace ( $except . '|', '', $botchar ) : ''; + if (preg_match ( $botchar, $ua )) { + return true; + } + return false; + } + /** * 客户操作日志 * @param string $type 操作类型 login reg add edit view delete down join sign play order pay @@ -321,7 +335,7 @@ function add_user_log($type, $param_str = '', $param_id = 0, $param = []) case 'delete': $title = '删除'; break; - case 'down': + case 'down': $title = '下载'; break; case 'join': @@ -339,10 +353,10 @@ function add_user_log($type, $param_str = '', $param_id = 0, $param = []) case 'pay': $title = '支付'; break; - case 'api': + case 'api': $title = 'API请求'; break; - case 'install': + case 'install': $title = '安装'; break; default: @@ -350,7 +364,7 @@ function add_user_log($type, $param_str = '', $param_id = 0, $param = []) break; } if ($type == 'login') { - $login_user = \think\facade\Db::name('user')->where(array('id' => $param_id))->find(); + $login_user = \think\facade\Db::name('User')->where(array('id' => $param_id))->find(); if ($login_user['nickname'] == '') { $login_user['nickname'] = $login_user['name']; } @@ -363,6 +377,11 @@ function add_user_log($type, $param_str = '', $param_id = 0, $param = []) $login_user = []; $login_user['id'] = 0; $login_user['nickname'] = '游客'; + if(isRobot()){ + $login_user['nickname'] = '蜘蛛'; + $type = 'spider'; + $title = '爬行'; + } } else { if ($login_user['nickname'] == '') { $login_user['nickname'] = $login_user['username']; @@ -386,7 +405,7 @@ function add_user_log($type, $param_str = '', $param_id = 0, $param = []) $data['function'] = app('request')->action(); $data['ip'] = $request->ip(); $data['create_time'] = time(); - \think\facade\Db::name('user_log')->strict(false)->field(true)->insert($data); + \think\facade\Db::name('UserLog')->strict(false)->field(true)->insert($data); } /** diff --git a/app/home/view/user/index.html b/app/home/view/user/index.html index 655619c..840a6d0 100644 --- a/app/home/view/user/index.html +++ b/app/home/view/user/index.html @@ -14,9 +14,7 @@
- +