Loading
0

PHP代码获取操作系统版本以及手机系统版本方法
被墙跳转TG:@qianhenetwork QQ 851617266

301免备案跳转微信公众号
腾讯云服务器大促销。
华为服务器

前言:通过PHP语言实际开发中,我们需要获取用户本地的操作系统版本,比如识别用户使用的是什么系统,或者获取手机的系统型号,本教程介绍如何通过php代码获取操作系统版本以及手机系统型号方法。
代码如下:
方法1:(亲测有效,可看演示:https://ip.tag.gg

<?php
function userOS()
{
    $agent =  $_SERVER['HTTP_USER_AGENT'];
    $os = false;

    if (preg_match('/win/i', $agent) && strpos($agent, '95'))
    {
        $os = 'Windows 95';
    }
    elseif (preg_match('/win 9x/i', $agent) && strpos($agent, '4.90'))
    {
        $os = 'Windows ME';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/98/i', $agent))
    {
        $os = 'Windows 98';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/nt 6.0/i', $agent))
    {
        $os = 'Windows Vista';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/nt 6.1/i', $agent))
    {
        $os = 'Windows 7';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/nt 6.2/i', $agent))
    {
        $os = 'Windows 8';
    }elseif(preg_match('/win/i', $agent) && preg_match('/nt 10.0/i', $agent))
    {
        $os = 'Windows 10 or Windows 11';#添加win10判断
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/nt 5.1/i', $agent))
    {
        $os = 'Windows XP';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/nt 5/i', $agent))
    {
        $os = 'Windows 2000';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/nt/i', $agent))
    {
        $os = 'Windows NT';
    }
    elseif (preg_match('/win/i', $agent) && preg_match('/32/i', $agent))
    {
        $os = 'Windows 32';
    }
    elseif (preg_match('/iPhone/i', $agent))
    {
        $os = 'iPhone';
    }
    elseif (preg_match('/iPad/i', $agent))
    {
        $os = 'iPad';
    }
    elseif (preg_match('/Android/i', $agent))
    {
        $os = 'Android';
    }
    elseif (preg_match('/Mac/i', $agent) && preg_match('/OS/i', $agent))
    {
        $os = 'Mac OS';
    }
    elseif (preg_match('/PowerPC/i', $agent))
    {
        $os = 'PowerPC';
    }
    elseif (preg_match('/linux/i', $agent))
    {
        $os = 'Linux';
    }
    elseif (preg_match('/unix/i', $agent))
    {
        $os = 'Unix';
    }
    elseif (preg_match('/sun/i', $agent) && preg_match('/os/i', $agent))
    {
        $os = 'SunOS';
    }
    elseif (preg_match('/ibm/i', $agent) && preg_match('/os/i', $agent))
    {
        $os = 'IBM OS/2';
    }
    elseif (preg_match('/AIX/i', $agent))
    {
        $os = 'AIX';
    }
    elseif (preg_match('/HPUX/i', $agent))
    {
        $os = 'HPUX';
    }
    elseif (preg_match('/NetBSD/i', $agent))
    {
        $os = 'NetBSD';
    }
    elseif (preg_match('/BSD/i', $agent))
    {
        $os = 'BSD';
    }
    elseif (preg_match('/OSF1/i', $agent))
    {
        $os = 'OSF1';
    }
    elseif (preg_match('/IRIX/i', $agent))
    {
        $os = 'IRIX';
    }
    elseif (preg_match('/FreeBSD/i', $agent))
    {
        $os = 'FreeBSD';
    }
    elseif (preg_match('/teleport/i', $agent))
    {
        $os = 'teleport';
    }
    elseif (preg_match('/flashget/i', $agent))
    {
        $os = 'flashget';
    }
    elseif (preg_match('/webzip/i', $agent))
    {
        $os = 'webzip';
    }
    elseif (preg_match('/offline/i', $agent))
    {
        $os = 'offline';
    }
    else
    {
        $os = '未知系统';
    }
    return $os;
}


?>

方法2:亲测有效

<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
    if (stripos($user_agent, "iPhone")!==false) {
        $brand = 'iPhone';
    } else if (stripos($user_agent, "SAMSUNG")!==false || stripos($user_agent, "Galaxy")!==false || strpos($user_agent, "GT-")!==false || strpos($user_agent, "SCH-")!==false || strpos($user_agent, "SM-")!==false) {
        $brand = '三星';
    } else if (stripos($user_agent, "Huawei")!==false || stripos($user_agent, "Honor")!==false || stripos($user_agent, "H60-")!==false || stripos($user_agent, "H30-")!==false) {
        $brand = '华为';
    } else if (stripos($user_agent, "Lenovo")!==false) {
        $brand = '联想';
    } else if (strpos($user_agent, "MI-ONE")!==false || strpos($user_agent, "MI 1S")!==false || strpos($user_agent, "MI 2")!==false || strpos($user_agent, "MI 3")!==false || strpos($user_agent, "MI 4")!==false || strpos($user_agent, "MI-4")!==false) {
        $brand = '小米';
    } else if (strpos($user_agent, "HM NOTE")!==false || strpos($user_agent, "HM201")!==false) {
        $brand = '红米';
    } else if (stripos($user_agent, "Coolpad")!==false || strpos($user_agent, "8190Q")!==false || strpos($user_agent, "5910")!==false) {
        $brand = '酷派';
    } else if (stripos($user_agent, "ZTE")!==false || stripos($user_agent, "X9180")!==false || stripos($user_agent, "N9180")!==false || stripos($user_agent, "U9180")!==false) {
        $brand = '中兴';
    } else if (stripos($user_agent, "OPPO")!==false || strpos($user_agent, "X9007")!==false || strpos($user_agent, "X907")!==false || strpos($user_agent, "X909")!==false || strpos($user_agent, "R831S")!==false || strpos($user_agent, "R827T")!==false || strpos($user_agent, "R821T")!==false || strpos($user_agent, "R811")!==false || strpos($user_agent, "R2017")!==false) {
        $brand = 'OPPO';
    } else if (strpos($user_agent, "HTC")!==false || stripos($user_agent, "Desire")!==false) {
        $brand = 'HTC';
    } else if (stripos($user_agent, "vivo")!==false) {
        $brand = 'vivo';
    } else if (stripos($user_agent, "K-Touch")!==false) {
        $brand = '天语';
    } else if (stripos($user_agent, "Nubia")!==false || stripos($user_agent, "NX50")!==false || stripos($user_agent, "NX40")!==false) {
        $brand = '努比亚';
    } else if (strpos($user_agent, "M045")!==false || strpos($user_agent, "M032")!==false || strpos($user_agent, "M355")!==false) {
        $brand = '魅族';
    } else if (stripos($user_agent, "DOOV")!==false) {
        $brand = '朵唯';
    } else if (stripos($user_agent, "GFIVE")!==false) {
        $brand = '基伍';
    } else if (stripos($user_agent, "Gionee")!==false || strpos($user_agent, "GN")!==false) {
        $brand = '金立';
    } else if (stripos($user_agent, "HS-U")!==false || stripos($user_agent, "HS-E")!==false) {
        $brand = '海信';
    } else if (stripos($user_agent, "Nokia")!==false) {
        $brand = '诺基亚';
    } else {
        $brand = '其他手机';
    }
echo $brand;
?>





 
301免备案跳转微信公众号
华为服务器
腾讯云服务器大促销。

声明:站长码字很辛苦啊,转载时请保留本声明及附带文章链接:https://www.zfcdn.xyz/showinfo-3-36266-0.html
亲爱的:被墙域名跳转TG:@qianhenetwork QQ:851617266,可否收藏+评论+分享呢?
上一篇:解决linux图形界面:Failed to execute default web browser报错
下一篇:不进入Docker容器查看容器内部端口监听的方法