PHP获取访客系统或手机品牌
以前的博客曾写过一个功能,就是显示留言或者评论者的电脑操作系统、手机端显示手机品牌,因为以前的程序数据全都丢失了,今天又重新写了一个方法。主要是判断UserAget,收集了常见的操作系统及手机品牌。
/** * 获取操作系统、手机品牌 * Author:熊海 * Time:2021-05-25 11:00 * Website:http://www.imxh.cn * @return boolean|string * */ function get_os(){ $UserAgent=$_SERVER['HTTP_USER_AGENT']; $os = false; if (preg_match('/Win/i',$UserAgent) && stripos($UserAgent, 'NT 10')){ $os = 'Win 10'; }else if (preg_match('/Win/i',$UserAgent) && stripos($UserAgent, 'NT 6.1')){ $os = 'Win 7'; }else if (preg_match('/Win/i',$UserAgent) && stripos($UserAgent, 'NT 6.0')){ $os = 'Vista'; }else if (preg_match('/Win/i',$UserAgent) && stripos($UserAgent, 'NT 5.2')){ $os = 'Win 2003'; }else if (preg_match('/Win/i',$UserAgent) && stripos($UserAgent, 'NT 5.1')){ $os = 'Win XP'; }else if (preg_match('/Win/i',$UserAgent) && stripos($UserAgent, 'NT 5.0')){ $os = 'Win 2000'; }else if (stripos($UserAgent, "SAMSUNG") || stripos($UserAgent, "Galaxy") || stripos($UserAgent, "GT-") || stripos($UserAgent, "SCH-") || stripos($UserAgent, "SM-")) { $os = '三星'; }else if (stripos($UserAgent, 'Huawei')|| stripos($UserAgent, "Honor")){ $os = '华为'; }else if (stripos($UserAgent, 'Lenovo')){ $os = '联想'; }else if (stripos($UserAgent, 'xiaomi')){ $os = '小米'; }else if (stripos($UserAgent, 'Coolpad')){ $os = '酷派'; }else if (stripos($UserAgent, 'ZTE')){ $os = '中兴'; }else if (stripos($UserAgent, 'OPPO') || stripos($UserAgent, 'PDEM')){ $os = 'OPPO'; }else if (stripos($UserAgent, 'HTC')){ $os = 'HTC'; }else if (stripos($UserAgent, 'vivo')){ $os = 'ViVo'; }else if (stripos($UserAgent, 'K-Touch')){ $os = '天语'; }else if (stripos($UserAgent, 'Nubia')){ $os = '努比亚'; }else if (stripos($UserAgent, 'DOOV')){ $os = '朵唯'; }else if (stripos($UserAgent, 'Nokia')){ $os = '诺基亚'; }else if (stripos($UserAgent, 'iPad')){ $os = 'iPad'; }else if (stripos($UserAgent, 'iPhone')){ $os = 'iPhone'; }else if (stripos($UserAgent, 'Mac')){ $os = 'Mac'; }else if (stripos($UserAgent, 'Android')){ $os = 'Android'; }else if (stripos($UserAgent, 'Linux')){ $os = 'Linux'; }else if (stripos($UserAgent, 'Unix')){ $os = 'Unix'; }else{ $os = 'Other'; } return $os; }
共 1 条评论