A-A+

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

2020年01月18日 我爱编程 暂无评论

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

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

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

给我留言

Copyright © 四季博客 保留所有权利.   Theme  Ality

用户登录