排行榜 统计
  • 建站日期:2020/07/11
  • 文章总数:151 篇
  • 评论总数:377 条
  • 分类总数:5 个
  • 最后更新:1月17日

Typecho评论者UA&OS获取

本文阅读 1 分钟
首页 typecho 正文

本文最后更新于2022年12月23日, 已超过462天没有更新。 如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

创建自定义函数

/**
* 浏览器及操作系统判断
*
* @param string $agent 系统数据库中访者数据
*/

/** 获取浏览器信息 */
function getBrowser($agent)
{
    if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
        $outputer = 'Internet Explorer' . ' ' . $regs[1];
    } else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
        $outputer = 'Mozilla FireFox' . ' ' . $regs[1];
    } else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
        $outputer = 'Maxthon' . ' ' . $regs[2];
    } else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) {
        $outputer = 'Google Chrome' . ' ' . $regs[2];
    } else if (preg_match('/QQBrowser\/([^\s]+)/i', $agent, $regs)) {
        $regg = explode("/",$regs[1]);
        $outputer = 'QQ浏览器' . ' ' . $regg[0];
    } else if (preg_match('/UC/i', $agent)) {
        $outputer = 'UCWeb' . ' ' . '8.11112510';
    } else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
        $outputer = 'Apple Safari' . ' ' . $regs[1];
    } else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
        $outputer = 'Opera' . ' ' . $regs[1];
    } else {
        $outputer = '其它浏览器';
    }

    echo $outputer;
}

/** 获取操作系统信息 */
function getOs($agent)
{
    $os = false;

    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 5.1/i', $agent)) {
            $os = 'Windows XP';
        } else if (preg_match('/nt 5/i', $agent)) {
            $os = 'Windows 2000';
        } else {
            $os = 'Windows';
        }
    } else if (preg_match('/android/i', $agent)) {
        $os = 'Android';
    } else if (preg_match('/ubuntu/i', $agent)) {
        $os = 'Ubuntu';
    } else if (preg_match('/linux/i', $agent)) {
        $os = 'Linux';
    } else if (preg_match('/mac/i', $agent)) {
        $os = 'Mac OS X';
    } else if (preg_match('/unix/i', $agent)) {
        $os = 'Unix';
    } else if (preg_match('/symbian/i', $agent)) {
        $os = 'Nokia SymbianOS';
    } else {
        $os = '其它操作系统';
    }

    echo $os;
}

然后在comments适当的地方调用

此处内容需要评论回复后查看

本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
Typecho网站底部展示网站运行时间标签
« 上一篇 08-02
修改Typecho评论调用QQ头像
下一篇 » 08-06