栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php获取用户系统名称信息

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php获取用户系统名称信息

    php通过用户代理头获取来访用户的系统名信息,使用超全局变量$_SERVER['HTTP_USER_AGENT']返回字符串进行匹配得到相应的系统名称。

详细代码:

function get_os(){

    $agent = $_SERVER['HTTP_USER_AGENT'];
    $os = false;
 
    if (preg_match('/win/i', $agent) && strpos($agent, '95'))
    {
    
      $os = 'Windows 95';
      
    }
    else if (preg_match('/win 9x/i', $agent) && strpos($agent, '4.90'))
    {
    
      $os = 'Windows ME';
      
    }
    else if (preg_match('/win/i', $agent) && preg_match('/98/i', $agent))
    {
    
      $os = 'Windows 98';
      
    }
    else if (preg_match('/win/i', $agent) && preg_match('/nt 6.0/i', $agent))
    {
    
      $os = 'Windows Vista';
      
    }
    else if (preg_match('/win/i', $agent) && preg_match('/nt 6.1/i', $agent))
    {
    
      $os = 'Windows 7';
      
    }
      else if (preg_match('/win/i', $agent) && preg_match('/nt 6.2/i', $agent))
    {
    
      $os = 'Windows 8';
      
    }else if(preg_match('/win/i', $agent) && preg_match('/nt 10.0/i', $agent))
    {
    
      $os = 'Windows 10';
      
    }else if (preg_match('/win/i', $agent) && preg_match('/nt 5.1/i', $agent))
    {
    
      $os = 'Windows XP';
      
    }
    else if (preg_match('/win/i', $agent) && preg_match('/nt 5/i', $agent))
    {
    
      $os = 'Windows 2000';
      
    }
    else if (preg_match('/win/i', $agent) && preg_match('/nt/i', $agent))
    {
    
      $os = 'Windows NT';
      
    }
    else if (preg_match('/win/i', $agent) && preg_match('/32/i', $agent))
    {
    
      $os = 'Windows 32';
      
    }
    else if (preg_match('/linux/i', $agent))
    {
    
      $os = 'Linux';
      
    }
    else if (preg_match('/unix/i', $agent))
    {
    
      $os = 'Unix';
      
    }
    else if (preg_match('/sun/i', $agent) && preg_match('/os/i', $agent))
    {
    
      $os = 'SunOS';
      
    }
    else if (preg_match('/ibm/i', $agent) && preg_match('/os/i', $agent))
    {
    
      $os = 'IBM OS/2';
      
    }
    else if (preg_match('/Mac/i', $agent) && preg_match('/PC/i', $agent))
    {
    
      $os = 'Macintosh';
      
    }
    else if (preg_match('/PowerPC/i', $agent))
    {
    
      $os = 'PowerPC';
      
    }
    else if (preg_match('/AIX/i', $agent))
    {
    
      $os = 'AIX';
      
    }
    else if (preg_match('/HPUX/i', $agent))
    {
    
      $os = 'HPUX';
      
    }
    else if (preg_match('/NetBSD/i', $agent))
    {
    
      $os = 'NetBSD';
      
    }
    else if (preg_match('/BSD/i', $agent))
    {
    
      $os = 'BSD';
      
    }
    else if (preg_match('/OSF1/i', $agent))
    {
    
      $os = 'OSF1';
      
    }
    else if (preg_match('/IRIX/i', $agent))
    {
    
      $os = 'IRIX';
      
    }
    else if (preg_match('/FreeBSD/i', $agent))
    {
    
      $os = 'FreeBSD';
      
    }
    else if (preg_match('/teleport/i', $agent))
    {
    
      $os = 'teleport';
      
    }
    else if (preg_match('/flashget/i', $agent))
    {
    
      $os = 'flashget';
      
    }
    else if (preg_match('/webzip/i', $agent))
    {
    
      $os = 'webzip';
      
    }
    else if (preg_match('/offline/i', $agent))
    {
    
      $os = 'offline';
      
    }else if (preg_match('/iPhone OS 8/i', $agent))
    {
    
      $os = 'iOS 8';
      
    }else if (preg_match('/YisouSpider/i', $agent))
    {
    
      $os = '一搜引擎';
      
    }else if (preg_match('/Yahoo! Slurp/i', $agent))
    {
    
      $os = '雅虎引擎';
      
    }else if (preg_match('/iPhone OS 6/i', $agent))
    {
    
      $os = 'iOS 6';
      
    }
    else if (preg_match('/Baiduspider/i', $agent))
    {
    
      $os = '百度引擎';
      
    }else if (preg_match('/iPhone OS 10/i', $agent))
    {
    
      $os = 'iOS 10';
      
    }else if (preg_match('/Mac OS X 10/i', $agent))
    {
    
      $os = 'Mac OS 10';
      
    }
    else if (preg_match('/Ahrefs/i', $agent))
    {
    
      $os = 'Ahrefs SEO 引擎';
      
    }
    else if (preg_match('/JikeSpider/i', $agent))
    {
    
      $os = '即刻引擎';
      
    }else if (preg_match('/Googlebot/i', $agent))
    {
    
      $os = '谷歌引擎';
      
    }else if(preg_match('/bingbot/i',$agent))
    {
    
        $os = '必应引擎';
         
    }else if(preg_match('/iPhone OS 7/i',$agent))
    {
    
        $os = 'iOS 7';
        
    }else if(preg_match('/Sogou web spider/i',$agent))
    {
    
        $os = '搜狗引擎';
        
    }else if(preg_match('/IP-Guide.com Crawler/i',$agent))
    {
    
        $os = 'IP-Guide Crawler 引擎';
        
    }else if(preg_match('/VenusCrawler/i',$agent))
    {
    
        $os = 'VenusCrawler 引擎';
        
    }
    else
    {
    
      $os = $agent;
      
    }
    
    return $os;
      
   }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/2494.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号