廿四、PHP判断用户访问的操作系统,以及iOS的设备

2018-11-22  本文已影响16人  yuzhan550
<?php
function getOS(){
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if(strpos($agent, 'windows nt')) {
    $platform = 'windows';
    } elseif(strpos($agent, 'macintosh')) {
    $platform = 'mac';
    } elseif(strpos($agent, 'ipod')) {
    $platform = 'ipod';
    } elseif(strpos($agent, 'ipad')) {
    $platform = 'ipad';
    } elseif(strpos($agent, 'iphone')) {
    $platform = 'iphone';
    } elseif (strpos($agent, 'android')) {
    $platform = 'android';
    } elseif(strpos($agent, 'unix')) {
    $platform = 'unix';
    } elseif(strpos($agent, 'linux')) {
    $platform = 'linux';
    } else {
    $platform = 'other';
    }

    return $platform;
}
echo getOS();

参考:https://www.xiariboke.com/article/1141.html

上一篇下一篇

猜你喜欢

热点阅读