首页 > 开发 > PHP > 正文

php如何判断访问系统的用户设备类型(代码示例)

2024-05-04 22:01:55
字体:
来源:转载
供稿:网友

本篇文章给大家带来的内容是关于php如何判断访问系统的用户设备类型(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

当今的电子设备越来越多,我们在开发过程中往往也需要分析用户使用的电子设备类型。下面是采用PHP代码来获取用户使用的哪些类型的电子设备来访问自己的平台。

  1. /** 
  2.  * 用户设备类型 
  3.  * @return string 
  4.  */ 
  5. function clientOS() { 
  6.  
  7.     $agent = strtolower($_SERVER['HTTP_USER_AGENT']); 
  8.  
  9.     if(strpos($agent'windows nt')) { 
  10.         $platform = 'windows'
  11.     } elseif(strpos($agent'macintosh')) { 
  12.         $platform = 'mac'
  13.     } elseif(strpos($agent'ipod')) { 
  14.         $platform = 'ipod'
  15.     } elseif(strpos($agent'ipad')) { 
  16.         $platform = 'ipad'
  17.     } elseif(strpos($agent'iphone')) { 
  18.         $platform = 'iphone'
  19.     } elseif (strpos($agent'android')) { 
  20.         $platform = 'android'
  21.     } elseif(strpos($agent'unix')) { 
  22.         $platform = 'unix'
  23.     } elseif(strpos($agent'linux')) { 
  24.         $platform = 'linux'
  25.     } else { 
  26.         $platform = 'other'
  27.     } //Vevb.com 
  28.  
  29.     return $platform

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表