Typecho评论者UA&OS获取

Typecho评论者UA&OS获取

Laoyao
2020-08-06 / 0 评论 / 1,399 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年12月23日,已超过860天没有更新,若内容或图片失效,请留言反馈。

创建自定义函数

/**
* 浏览器及操作系统判断
*
* @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适当的地方调用

[hide]

<?php getBrowser($comments->agent); ?> @ <?php getOs($comments->agent); ?>

[/hide]

3

评论

博主关闭了当前页面的评论