网站首页
网站相关
Typecho
Emlog
素材分享
软件工具
游戏程序
Search
1
欧洲卡车模拟2中文破解版
34 阅读
2
网易云/酷狗/酷我/全民音乐API
26 阅读
3
班迪录屏软件免安装破解版
25 阅读
4
【ATS/ETS2】TS存档编辑器 V0.3.10
17 阅读
5
21款动态懒加载图
14 阅读
Search
标签搜索
模版
GTA5
侠盗猎车
模拟
录屏
懒加载
插件
API
域名
DNS
解析
HTML
相册
泡泡龙
累计撰写
39
篇文章
累计收到
3
条评论
首页
栏目
网站相关
Typecho
Emlog
素材分享
软件工具
游戏程序
页面
搜索到
11
篇与
的结果
Typecho非插件实现评论IP属地显示
在 functions.php 文件里添加以下代码;/** 获取评论者地址 */ function convertip($ip){ $ip1num = 0; $ip2num = 0; $ipAddr1 =""; $ipAddr2 =""; $dat_path = './qqwry.dat'; if(!preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $ip)) { return 'IP 数据库路径不对'; } if(!$fd = @fopen($dat_path, 'rb')){ return 'IP 数据库路径不正确'; } $ip = explode('.', $ip); $ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3]; $DataBegin = fread($fd, 4); $DataEnd = fread($fd, 4); $ipbegin = implode('', unpack('L', $DataBegin)); if($ipbegin < 0) $ipbegin += pow(2, 32); $ipend = implode('', unpack('L', $DataEnd)); if($ipend < 0) $ipend += pow(2, 32); $ipAllNum = ($ipend - $ipbegin) / 7 + 1; $BeginNum = 0; $EndNum = $ipAllNum; while($ip1num>$ipNum || $ip2num<$ipNum) { $Middle= intval(($EndNum + $BeginNum) / 2); fseek($fd, $ipbegin + 7 * $Middle); $ipData1 = fread($fd, 4); if(strlen($ipData1) < 4) { fclose($fd); return 'System Error'; } $ip1num = implode('', unpack('L', $ipData1)); if($ip1num < 0) $ip1num += pow(2, 32); if($ip1num > $ipNum) { $EndNum = $Middle; continue; } $DataSeek = fread($fd, 3); if(strlen($DataSeek) < 3) { fclose($fd); return 'System Error'; } $DataSeek = implode('', unpack('L', $DataSeek.chr(0))); fseek($fd, $DataSeek); $ipData2 = fread($fd, 4); if(strlen($ipData2) < 4) { fclose($fd); return 'System Error'; } $ip2num = implode('', unpack('L', $ipData2)); if($ip2num < 0) $ip2num += pow(2, 32); if($ip2num < $ipNum) { if($Middle == $BeginNum) { fclose($fd); return 'Unknown'; } $BeginNum = $Middle; } } $ipFlag = fread($fd, 1); if($ipFlag == chr(1)) { $ipSeek = fread($fd, 3); if(strlen($ipSeek) < 3) { fclose($fd); return 'System Error'; } $ipSeek = implode('', unpack('L', $ipSeek.chr(0))); fseek($fd, $ipSeek); $ipFlag = fread($fd, 1); } if($ipFlag == chr(2)) { $AddrSeek = fread($fd, 3); if(strlen($AddrSeek) < 3) { fclose($fd); return 'System Error'; } $ipFlag = fread($fd, 1); if($ipFlag == chr(2)) { $AddrSeek2 = fread($fd, 3); if(strlen($AddrSeek2) < 3) { fclose($fd); return 'System Error'; } $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0))); fseek($fd, $AddrSeek2); } else { fseek($fd, -1, SEEK_CUR); } while(($char = fread($fd, 1)) != chr(0)) $ipAddr2 .= $char; $AddrSeek = implode('', unpack('L', $AddrSeek.chr(0))); fseek($fd, $AddrSeek); while(($char = fread($fd, 1)) != chr(0)) $ipAddr1 .= $char; } else { fseek($fd, -1, SEEK_CUR); while(($char = fread($fd, 1)) != chr(0)) $ipAddr1 .= $char; $ipFlag = fread($fd, 1); if($ipFlag == chr(2)) { $AddrSeek2 = fread($fd, 3); if(strlen($AddrSeek2) < 3) { fclose($fd); return 'System Error'; } $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0))); fseek($fd, $AddrSeek2); } else { fseek($fd, -1, SEEK_CUR); } while(($char = fread($fd, 1)) != chr(0)){ $ipAddr2 .= $char; } } fclose($fd); if(preg_match('/http/i', $ipAddr2)) { $ipAddr2 = ''; } $ipaddr = "$ipAddr1 $ipAddr2"; $ipaddr = preg_replace('/CZ88.NET/is', '', $ipaddr); $ipaddr = preg_replace('/^s*/is', '', $ipaddr); $ipaddr = preg_replace('/s*$/is', '', $ipaddr); if(preg_match('/http/i', $ipaddr) || $ipaddr == '') { $ipaddr = '可能来自火星'; } $ipaddr = iconv('gbk', 'utf-8//IGNORE', $ipaddr); return $ipaddr; }注:如只想显示地区,不显示后面的网络(移动/联通),请把 $ipaddr = "$ipAddr1 $ipAddr2"; 改为 $ipaddr = "$ipAddr1";添加完代码后把 qqwry.dat 上传至程序安装根目录,下载地址:https://xxav.sbs/qqwry.dat找到输出评论表单文件 comments.php ,在需要的地方添加如下代码;<?php echo convertip($comments->ip); ?>如果网站配置了CDN,请在网站根目录 config.inc.php 添加如下代码即可绕过CDN获取用户真实IP属地;//绕过 CDN 代理获取真实 IP if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){ $list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = $list[0];}
2023年09月28日
11 阅读
0 评论
1 点赞
Typecho非插件实现评论显示系统浏览器及IP
1.将如下代码粘贴在 functions.php 文件种;/** * 浏览器和设备信息 * * @param string $userAgent 用户代理 * @return string[] */ function getBrowsersInfo ($userAgent) { $deviceInfo = [ "system" => "", "systemVersion" => "", "browser" => "", "version" => "", "device" => "PC" ]; $match = [ // 浏览器 - 国外浏览器 "Safari" => strstr($userAgent, 'Safari') != false , "Chrome" => strstr($userAgent, 'Chrome') != false || strstr($userAgent, 'CriOS') != false , "IE" => strstr($userAgent, 'MSIE') != false || strstr($userAgent, 'Trident') != false , "Edge" => strstr($userAgent, 'Edge') != false || strstr($userAgent, 'Edg/') != false || strstr($userAgent, 'EdgA') != false || strstr($userAgent, 'EdgiOS') != false, "Firefox" => strstr($userAgent, 'Firefox') != false || strstr($userAgent, 'FxiOS') != false , "Firefox Focus" => strstr($userAgent, 'Focus') != false, "Chromium" => strstr($userAgent,'Chromium') != false, "Opera" => strstr($userAgent,'Opera') != false || strstr($userAgent,'OPR') != false, "Vivaldi" => strstr($userAgent,'Vivaldi') != false, "Yandex" => strstr($userAgent,'YaBrowser') != false, "Arora" => strstr($userAgent,'Arora') != false, "Lunascape" => strstr($userAgent,'Lunascape') != false, "QupZilla" => strstr($userAgent,'QupZilla') != false, "Coc Coc" => strstr($userAgent,'coc_coc_browser') != false, "Kindle" => strstr($userAgent,'Kindle') != false || strstr($userAgent,'Silk/') != false, "Iceweasel" => strstr($userAgent,'Iceweasel') != false, "Konqueror" => strstr($userAgent,'Konqueror') != false, "Iceape" => strstr($userAgent,'Iceape') != false, "SeaMonkey" => strstr($userAgent,'SeaMonkey') != false, "Epiphany" => strstr($userAgent,'Epiphany') != false, // 浏览器 - 国内浏览器 "360" => strstr($userAgent,'QihooBrowser') != false || strstr($userAgent,'QHBrowser') != false, "360EE" => strstr($userAgent,'360EE') != false, "360SE" => strstr($userAgent,'360SE') != false, "UC" => strstr($userAgent,'UCBrowser') != false || strstr($userAgent,' UBrowser') != false || strstr($userAgent,'UCWEB') != false, "QQBrowser" => strstr($userAgent,'QQBrowser') != false, "QQ" => strstr($userAgent,'QQ/') != false, "Baidu" => strstr($userAgent,'Baidu') != false || strstr($userAgent,'BIDUBrowser') != false || strstr($userAgent,'baidubrowser') != false || strstr($userAgent,'baiduboxapp') != false || strstr($userAgent,'BaiduHD') != false, "Maxthon" => strstr($userAgent,'Maxthon') != false, "Sogou" => strstr($userAgent,'MetaSr') != false || strstr($userAgent,'Sogou') != false, "Liebao" => strstr($userAgent,'LBBROWSER') != false || strstr($userAgent,'LieBaoFast') != false, "2345Explorer" => strstr($userAgent,'2345Explorer') != false || strstr($userAgent,'Mb2345Browser') != false || strstr($userAgent,'2345chrome') != false, "115Browser" => strstr($userAgent,'115Browser') != false, "TheWorld" => strstr($userAgent,'TheWorld') != false, "Quark" => strstr($userAgent,'Quark') != false, "Qiyu" => strstr($userAgent,'Qiyu') != false, // 浏览器 - 手机厂商 "XiaoMi" => strstr($userAgent,'MiuiBrowser') != false, "Huawei" => strstr($userAgent,'HuaweiBrowser') != false || strstr($userAgent,'HUAWEI/') != false || strstr($userAgent,'HONOR') != false || strstr($userAgent,'HBPC/') != false, "Vivo" => strstr($userAgent,'VivoBrowser') != false, "OPPO" => strstr($userAgent,'HeyTapBrowser') != false, // 浏览器 - 客户端 "Wechat" => strstr($userAgent,'MicroMessenger') != false, "WechatWork" => strstr($userAgent,'wxwork/') != false, "Taobao" => strstr($userAgent,'AliApp(TB') != false, "Alipay" => strstr($userAgent,'AliApp(AP') != false, "Weibo" => strstr($userAgent,'Weibo') != false, "Douban" => strstr($userAgent,'com.douban.frodo') != false, "Suning" => strstr($userAgent,'SNEBUY-APP') != false, "iQiYi" => strstr($userAgent,'IqiyiApp') != false, "DingTalk" => strstr($userAgent,'DingTalk') != false, "Douyin" => strstr($userAgent,'aweme') != false, // 系统或平台 "Windows" => strstr($userAgent,'Windows') != false, "Linux" => strstr($userAgent,'Linux') != false || strstr($userAgent,'X11') != false, "Mac OS" => strstr($userAgent,'Macintosh') != false, "Android" => strstr($userAgent,'Android') != false || strstr($userAgent,'Adr') != false, "HarmonyOS" => strstr($userAgent,'HarmonyOS') != false, "Ubuntu" => strstr($userAgent,'Ubuntu') != false, "FreeBSD" => strstr($userAgent,'FreeBSD') != false, "Debian" => strstr($userAgent,'Debian') != false, "Windows Phone" => strstr($userAgent,'IEMobile') != false || strstr($userAgent,'Windows Phone') != false, "BlackBerry" => strstr($userAgent,'BlackBerry') != false || strstr($userAgent,'RIM') != false, "MeeGo" => strstr($userAgent,'MeeGo') != false, "Symbian" => strstr($userAgent,'Symbian') != false, "iOS" => strstr($userAgent,'like Mac OS X') != false, "Chrome OS" => strstr($userAgent,'CrOS') != false, "WebOS" => strstr($userAgent,'hpwOS') != false, // 设备 "Mobile" => strstr($userAgent,'Mobi') != false || strstr($userAgent,'iPh') != false || strstr($userAgent,'480') != false, "Tablet" => strstr($userAgent,'Tablet') != false || strstr($userAgent,'Pad') != false || strstr($userAgent,'Nexus 7') != false, ]; // 部分修正 | 因typecho评论数据只存储了ua的信息,所以不能完全进行修正尤其是360相关浏览器 if ($match['Baidu'] && $match['Opera']) $match['Baidu'] = false; if ($match['iOS']) $match['Safari'] = true; // 基本信息 $baseInfo = [ "browser" => [ 'Safari', 'Chrome', 'Edge', 'IE', 'Firefox', 'Firefox Focus', 'Chromium', 'Opera', 'Vivaldi', 'Yandex', 'Arora', 'Lunascape','QupZilla', 'Coc Coc', 'Kindle', 'Iceweasel', 'Konqueror', 'Iceape','SeaMonkey', 'Epiphany', 'XiaoMi', 'Vivo', 'OPPO', '360', '360SE','360EE', 'UC', 'QQBrowser', 'QQ', 'Huawei', 'Baidu', 'Maxthon', 'Sogou', 'Liebao', '2345Explorer', '115Browser', 'TheWorld', 'Quark', 'Qiyu', 'Wechat', 'WechatWork', 'Taobao', 'Alipay', 'Weibo', 'Douban', 'Suning', 'iQiYi', 'DingTalk', 'Douyin' ], "system" => [ 'Windows', 'Linux', 'Mac OS', 'Android', 'HarmonyOS', 'Ubuntu', 'FreeBSD', 'Debian', 'iOS', 'Windows Phone', 'BlackBerry', 'MeeGo', 'Symbian', 'Chrome OS', 'WebOS' ], "device" => ['Mobile', 'Tablet'], ]; foreach ($baseInfo as $k => $v) { foreach ($v as $xv) { if ($match[$xv]) $deviceInfo[$k] = $xv; } } // 操作系统版本信息 $windowsVersion = [ '10' => "10", '6.4' => '10', '6.3' => '8.1', '6.2' => '8', '6.1' => '7', '6.0' => 'Vista', '5.2' => 'XP', '5.1' => 'XP', '5.0' => '2000', ]; $wv = pregMatch("/^Mozilla\/\d.0 \(Windows NT ([\d.]+)[;)].*$/", $userAgent); $HarmonyOSVersion = [ 10 => "2", 12 => "3" ]; $systemVersion = [ "Windows" => $windowsVersion[$wv] ?? $wv, "Android" => pregMatch("/^.*Android ([\d.]+);.*$/", $userAgent), "HarmonyOS" => $HarmonyOSVersion[pregMatch("/^Mozilla.*Android ([\d.]+)[;)].*$/", $userAgent)] ?? '', "iOS" => preg_replace("/_/", '.', pregMatch("/^.*OS ([\d_]+) like.*$/", $userAgent)), "Debian" => pregMatch("/^.*Debian\/([\d.]+).*$/", $userAgent), "Windows Phone" => pregMatch("/^.*Windows Phone( OS)? ([\d.]+);.*$/", $userAgent), "Mac OS" => preg_replace("/_/", '.',pregMatch("/^.*Mac OS X ([\d_]+).*$/", $userAgent)), "WebOS" => pregMatch("/^.*hpwOS\/([\d.]+);.*$/", $userAgent) ]; if ($systemVersion[$deviceInfo['system']]) { $deviceInfo['systemVersion'] = $systemVersion[$deviceInfo['system']]; if ($deviceInfo['systemVersion'] == $userAgent) $deviceInfo['systemVersion'] = ''; } // if ($deviceInfo['system'] == 'Windows' && $_windowsVersion) $deviceInfo['systemVersion'] = $_windowsVersion; // 浏览器版本信息 $browsers_360SE = [ 108 => '14.0', 86 => '13.0', 78 => '12.0', 69 => '11.0', 63 => '10.0', 55 => '9.1', 45 => '8.1', 42 => '8.0', 31 => '7.0', 21 => '6.3', ]; $browsers_360EE = [ 95 => '21', 86 => '13.0', 78 => '12.0', 69 => '11.0', 63 => '9.5', 55 => '9.0', 50 => '8.7', 30 => '7.5', ]; $browsers_liebao = [ 57 => '6.5', 49 => '6.0', 46 => '5.9', 42 => '5.3', 39 => '5.2', 34 => '5.0', 29 => '4.5', 21 => '4.0' ]; $browsers_2345 = [ 69 => '10.0', 55 => '9.9', 69 => '10.0', 55 => '9.9', 69 => '10.0', 55 => '9.9' ]; $chromeVersion = pregMatch('/^.*Chrome\/([\d]+).*$/', $userAgent); $browsersVersion = [ "Safari" => pregMatch("/^.*Version\/([\d.]+).*$/", $userAgent), "Chrome" => pregMatch("/^.*Chrome\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*CriOS\/([\d.]+).*$/", $userAgent), "IE" => pregMatch("/^.*MSIE ([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*rv:([\d.]+).*$/", $userAgent), "Edge" => pregMatch("/^.*Edge\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*Edg\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*EdgA\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*EdgiOS\/([\d.]+).*$/", $userAgent), "Firefox" => pregMatch("/^.*Firefox\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*FxiOS\/([\d.]+).*$/", $userAgent), "Firefox Focus" => pregMatch("/^.*Focus\/([\d.]+).*$/", $userAgent), "Chromium" => pregMatch("/^.*Chromium\/([\d.]+).*$/", $userAgent), "Opera" => pregMatch("/^.*Opera\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*OPR\/([\d.]+).*$/", $userAgent), "Vivaldi" => pregMatch("/^.*Vivaldi\/([\d.]+).*$/", $userAgent), "Yandex" => pregMatch("/^.*YaBrowser\/([\d.]+).*$/", $userAgent), "Brave" => pregMatch("/^.*Chrome\/([\d.]+).*$/", $userAgent), "Arora" => pregMatch("/^.*Arora\/([\d.]+).*$/", $userAgent), "Lunascape" => pregMatch("/^.*Lunascape[\/\s]([\d.]+).*$/", $userAgent), "QupZilla" => pregMatch("/^.*QupZilla[\/\s]([\d.]+).*$/", $userAgent), "Coc Coc" => pregMatch("/^.*coc_coc_browser\/([\d.]+).*$/", $userAgent), "Kindle" => pregMatch("/^.*Version\/([\d.]+).*$/", $userAgent), "Iceweasel" => pregMatch("/^.*Iceweasel\/([\d.]+).*$/", $userAgent), "Konqueror" => pregMatch("/^.*Konqueror\/([\d.]+).*$/", $userAgent), "Iceape" => pregMatch("/^.*Iceape\/([\d.]+).*$/", $userAgent), "SeaMonkey" => pregMatch("/^.*SeaMonkey\/([\d.]+).*$/", $userAgent), "Epiphany" => pregMatch("/^.*Epiphany\/([\d.]+).*$/", $userAgent), "360" => pregMatch("/^.*QihooBrowser(HD)?\/([\d.]+).*$/", $userAgent), "Maxthon" => pregMatch("/^.*Maxthon\/([\d.]+).*$/", $userAgent), "QQBrowser" => pregMatch("/^.*QQBrowser\/([\d.]+).*$/", $userAgent), "QQ" => pregMatch("/^.*QQ\/([\d.]+).*$/", $userAgent), "Baidu" => pregMatch("/^.*BIDUBrowser[\s\/]([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*baiduboxapp\/([\d.]+).*$/", $userAgent), "UC" => pregMatch("/^.*UC?Browser\/([\d.]+).*$/", $userAgent), "Sogou" => pregMatch("/^.*SE ([\d.X]+).*$/", $userAgent) ?? pregMatch("/^.*SogouMobileBrowser\/([\d.]+).*$/", $userAgent), "115Browser" => pregMatch("/^.*115Browser\/([\d.]+).*$/", $userAgent), "TheWorld" => pregMatch("/^.*TheWorld ([\d.]+).*$/", $userAgent), "XiaoMi" => pregMatch("/^.*MiuiBrowser\/([\d.]+).*$/", $userAgent), "Vivo" => pregMatch("/^.*VivoBrowser\/([\d.]+).*$/", $userAgent), "OPPO" => pregMatch("/^.*HeyTapBrowser\/([\d.]+).*$/", $userAgent), "Quark" => pregMatch("/^.*Quark\/([\d.]+).*$/", $userAgent), "Qiyu" => pregMatch("/^.*Qiyu\/([\d.]+).*$/", $userAgent), "Wechat" => pregMatch("/^.*MicroMessenger\/([\d.]+).*$/", $userAgent), "WechatWork" => pregMatch("/^.*wxwork\/([\d.]+).*$/", $userAgent), "Taobao" => pregMatch("/^.*AliApp\(TB\/([\d.]+).*$/", $userAgent), "Alipay" => pregMatch("/^.*AliApp\(AP\/([\d.]+).*$/", $userAgent), "Weibo" => pregMatch("/^.*weibo__([\d.]+).*$/", $userAgent), "Douban" => pregMatch("/^.*com.douban.frodo\/([\d.]+).*$/", $userAgent), "Suning" => pregMatch("/^.*SNEBUY-APP([\d.]+).*$/", $userAgent), "iQiYi" => pregMatch("/^.*IqiyiVersion\/([\d.]+).*$/", $userAgent), "DingTalk" => pregMatch("/^.*DingTalk\/([\d.]+).*$/", $userAgent), "Douyin" => pregMatch("/^.*app_version\/([\d.]+).*$/", $userAgent), "Huawei" => pregMatch("/^.*Version\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*HuaweiBrowser\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*HBPC\/([\d.]+).*$/", $userAgent), "360SE" => $browsers_360SE[$chromeVersion] ?? '', "360EE" => $browsers_360EE[$chromeVersion] ?? '', "Liebao" => pregMatch("/^.*LieBaoFast\/([\d.]+).*$/", $userAgent) ?? $browsers_liebao[$chromeVersion], "2345Explorer" => $browsers_2345[$chromeVersion] ?? pregMatch("/^.*2345Explorer\/([\d.]+).*$/", $userAgent) ?? pregMatch("/^.*Mb2345Browser\/([\d.]+).*$/", $userAgent), ]; if ($browsersVersion[$deviceInfo['browser']]) { $deviceInfo["version"] = $browsersVersion[$deviceInfo['browser']]; if ($deviceInfo["version"] == $userAgent) $deviceInfo['version'] = ''; } // 修正浏览器版本信息 $chrome = pregMatch('/\S+Browser/', $userAgent); if ($deviceInfo['browser'] == 'Chrome' && $chrome) { $deviceInfo['browser'] = $chrome; $deviceInfo['version'] = pregMatch('/^.*Browser\/([\d.]+).*$/', $userAgent); } return $deviceInfo; } /** * 返回符合正则的值 * * @param string $reg 正则 * @param string $sourceData 源数据 * @return mixed|void */ function pregMatch($reg, $sourceData) { if (preg_match($reg, $sourceData, $mat)) return $mat[1]; }2.找到输出评论表单文件 comments.php ,在需要显示的地方加入以下代码;<span id="device_comment_<?php $comments->sequence(); ?>" > <?php $data = getBrowsersInfo($comments->agent); ?> <span><?php echo $data['system']; ?> </span><!-- 输出操作系统 --> <span><?php echo $data['systemVersion']; ?> </span> · <!-- 输出操作系统版本号 --> <span><?php echo $data['browser']; ?> </span> <!-- 输出浏览器名称 --> <span><?php echo $data['version']; ?> </span> <!-- 输出IP地址,为了用户安全,可以删除 --> </span>3.Joe主题自带的获取操作系统及浏览器版本不太准确,找到 Joe/core/function.php 文件,将1中的代码替换掉 第43~116行 的代码(如下);/* 根据评论agent获取浏览器类型 */ function _getAgentBrowser($agent) { if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) { $outputer = 'Internet Explore'; } else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) { $outputer = 'FireFox'; } else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) { $outputer = 'MicroSoft Edge'; } else if (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) { $outputer = '360 Fast Browser'; } else if (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) { $outputer = 'MicroSoft Edge'; } else if (preg_match('/UC/i', $agent)) { $outputer = 'UC Browser'; } else if (preg_match('/QQ/i', $agent, $regs) || preg_match('/QQ Browser\/([^\s]+)/i', $agent, $regs)) { $outputer = 'QQ Browser'; } else if (preg_match('/UBrowser/i', $agent, $regs)) { $outputer = 'UC Browser'; } else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) { $outputer = 'Opera'; } else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) { $outputer = 'Google Chrome'; } else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) { $outputer = 'Safari'; } else { $outputer = 'Google Chrome'; } echo $outputer; } /* 根据评论agent获取设备类型 */ function _getAgentOS($agent) { $os = "Linux"; if (preg_match('/win/i', $agent)) { if (preg_match('/nt 6.0/i', $agent)) { $os = 'Windows Vista'; } else if (preg_match('/nt 6.1/i', $agent)) { $os = 'Windows 7'; } else if (preg_match('/nt 6.2/i', $agent)) { $os = 'Windows 8'; } else if (preg_match('/nt 6.3/i', $agent)) { $os = 'Windows 8.1'; } else if (preg_match('/nt 5.1/i', $agent)) { $os = 'Windows XP'; } else if (preg_match('/nt 10.0/i', $agent)) { $os = 'Windows 10'; } else { $os = 'Windows X64'; } } else if (preg_match('/android/i', $agent)) { if (preg_match('/android 9/i', $agent)) { $os = 'Android Pie'; } else if (preg_match('/android 8/i', $agent)) { $os = 'Android Oreo'; } else { $os = 'Android'; } } else if (preg_match('/ubuntu/i', $agent)) { $os = 'Ubuntu'; } else if (preg_match('/linux/i', $agent)) { $os = 'Linux'; } else if (preg_match('/iPhone/i', $agent)) { $os = 'iPhone'; } else if (preg_match('/mac/i', $agent)) { $os = 'MacOS'; } else if (preg_match('/fusion/i', $agent)) { $os = 'Android'; } else { $os = 'Linux'; } echo $os; }4.然后打开 Joe/public/comment.php 文件第116行,替换成如下下代码; <div class="agent"> <span id="device_comment_<?php $comments->sequence(); ?>" > <?php $data = getBrowsersInfo($comments->agent); ?> <span><?php echo $data['system']; ?> </span><!-- 输出操作系统 --> <span><?php echo $data['systemVersion']; ?> </span> · <!-- 输出操作系统版本号 --> <span><?php echo $data['browser']; ?> </span> <!-- 输出浏览器名称 --> <span><?php echo $data['version']; ?> </span> <!-- 输出IP地址,为了用户安全,可以删除 --> </span> </div>
2023年09月28日
11 阅读
0 评论
0 点赞
Typecho评论显示操作系统及浏览器插件
2023年09月24日
7 阅读
0 评论
0 点赞
2023-09-24
使用说明下载后将文件夹名改为 XQUserAgent,上传至网站目录的 /usr/plugins启用插件,在需要显示的地方(侧栏评论也可以)插入以下代码:<?php XQUserAgent_Plugin::render($comments->agent); ?>获取Windows11教程此修改要站点支持HTTPS以及必须是typecho1.1以上版本(要修改Typecho程序 介意可以绕过这个)找到根目录的/var/Typecho/Widget/Request.php文件 大概253行左右搜索getAgent就能找到把return $this->request->getAgent();注释掉然后插入以下代码即可兼容Windows11;if(isset($_COOKIE['win11'])){ return str_replace("Windows NT 10.0","Windows NT 11.0",$this->request->getAgent()); }else{ return $this->request->getAgent(); }下载地址{cloud title="Typecho评论显示操作系统及浏览器插件" type="lz" url="https://suxiaoq.lanzoul.com/iEud00n73nbi" password=""/}
TypechoIP归属地显示插件
2023年09月24日
7 阅读
0 评论
1 点赞
2023-09-24
插件说明插件支持IPV6和IPV4归属地获取并且 为了避免卡顿或者获取失败 数据库都是本地 不调用任何第三方API接口使用说明解压后修改文件夹名为 XQLocation,将插件上传至网站目录的 /usr/plugins 下在 Typecho 后台「插件管理」处启用插件在需要显示的地方插入以下代码:<?php XQLocation_Plugin::render($comments->ip); ?>如果是系统自带的评论框架,找到var/Widget/Comments/Archive.php大概为108行,插入以下代码;<?php XQLocation_Plugin::render($this->ip); ?>下载地址{cloud title="IP归属地显示插件" type="lz" url="https://suxiaoq.lanzoul.com/ipUtV10whrwf" password=""/}
1
2