首页 > 后端开发 > php教程 > 获取访客浏览器和操作系统

获取访客浏览器和操作系统

WBOY
发布: 2016-07-25 08:49:14
原创
1128 人浏览过
获取访客浏览器和操作系统
  1. $useragent=$useragent=$_SERVER['HTTP_USER_AGENT'];
  2. /*取得客户端浏览器版本*/
  3. function browser($ua) {
  4. if (stripos($ua, "Googlebot")) {
  5. $browser = "谷歌蜘蛛";
  6. }
  7. elseif(stripos($ua, "Baiduspider") !== false) {
  8. $browser = "百度蜘蛛";
  9. }
  10. elseif(stripos($ua, "Yahoo!") !== false) {
  11. $browser = "雅虎蜘蛛";
  12. }
  13. elseif(stripos($ua, "bingbot")) {
  14. $browser = "必应蜘蛛";
  15. }
  16. elseif(stripos($ua, "YRSpider")) {
  17. $browser = "云壤蜘蛛";
  18. }
  19. elseif(stripos($ua, "Yeti") !== false) {
  20. $browser = "Naver蜘蛛";
  21. }
  22. elseif(stripos($ua, "Maxthon")) {
  23. if (stripos($ua, "AppleWebKit")) {
  24. $browser = "遨游浏览器(极速模式)";
  25. }
  26. elseif(stripos($ua, "Trident")) {
  27. $browser = "遨游浏览器(兼容模式)";
  28. }
  29. elseif(stripos($ua, "MAXTHON 2.0")) {
  30. $browser = "遨游浏览器2.0";
  31. }
  32. }
  33. elseif(stripos($ua, "Firefox")) {
  34. $browser = "火狐浏览器";
  35. }
  36. elseif(stripos($ua, "Opera") == 0 && stripos($ua, "Presto")) {
  37. $browser = "Opera";
  38. }
  39. elseif(stripos($ua, "BIDUBrowser")) {
  40. if (stripos($ua, "Trident")) {
  41. $browser = "百度浏览器(兼容模式)";
  42. }
  43. elseif(stripos($ua, "AppleWebKit")) {
  44. $browser = "百度浏览器(极速模式)";
  45. }
  46. }
  47. elseif(stripos($ua, "Ruibin")) {
  48. $browser = "瑞影浏览器";
  49. }
  50. elseif(stripos($ua, "qihu theworld")) {
  51. if (stripos($ua, "Trident")) {
  52. $browser = "世界之窗浏览器";
  53. }
  54. elseif(stripos($ua, "AppleWebKit")) {
  55. $browser = "世界之窗浏览器(极速模式)";
  56. }
  57. }
  58. elseif(stripos($ua, "MetaSr")) {
  59. if (stripos($ua, "Trident")) {
  60. $browser = "搜狗高速浏览器(兼容模式)";
  61. }
  62. elseif(stripos($ua, "AppleWebKit")) {
  63. $browser = "搜狗高速浏览器(极速模式)";
  64. }
  65. }
  66. elseif(stripos($ua, "LBBROWSER")) {
  67. if (stripos($ua, "Trident")) {
  68. $browser = "猎豹浏览器(兼容模式)";
  69. }
  70. elseif(stripos($ua, "AppleWebKit")) {
  71. $browser = "猎豹浏览器(极速模式)";
  72. }
  73. }
  74. elseif(stripos($ua, "YLMFBR")) {
  75. $browser = "115浏览器";
  76. }
  77. elseif(stripos($ua, "QQBrowser")) {
  78. if (stripos($ua, "Trident")) {
  79. $browser = "QQ浏览器(兼容模式)";
  80. }
  81. elseif(stripos($ua, "AppleWebKit")) {
  82. $browser = "QQ浏览器(极速模式)";
  83. }
  84. }
  85. elseif(stripos($ua, "TencentTraveler")) {
  86. $browser = "腾讯TT浏览器";
  87. }
  88. elseif(stripos($ua, "TaoBrowser")) {
  89. if (stripos($ua, "Trident")) {
  90. $browser = "淘宝浏览器(兼容模式)";
  91. }
  92. elseif(stripos($ua, "AppleWebkit")) {
  93. $browser = "淘宝浏览器(极速模式)";
  94. }
  95. }
  96. elseif(stripos($ua, "CoolNovo")) {
  97. $browser = "枫树浏览器";
  98. }
  99. elseif(stripos($ua, "SaaYaa")) {
  100. $browser = "闪游浏览器";
  101. }
  102. elseif(stripos($ua, "360SE")) {
  103. $browser = "360安全浏览器";
  104. }
  105. elseif(stripos($ua, "360EE")) {
  106. if (stripos($ua, "Trident")) {
  107. $browser = "360极速浏览器(兼容模式)";
  108. }
  109. elseif(stripos($ua, "AppleWebkit")) {
  110. $browser = "360极速浏览器(极速模式)";
  111. }
  112. }
  113. elseif(stripos($ua, "Konqueror")) {
  114. $browser = "Konqueror";
  115. }
  116. elseif(stripos($ua, "Chrome")) {
  117. $browser = "谷歌浏览器";
  118. }
  119. elseif(stripos($ua, "Safari")) {
  120. $browser = "Safari";
  121. }
  122. elseif(stripos($ua, "MSIE")) {
  123. $ver = explode(";", substr($ua, stripos($ua, "MSIE") + 5, 4));
  124. $ver = $ver[0];
  125. $browser = "IE ".$ver;
  126. }
  127. elseif(stripos($ua, "UCWEB")) {
  128. $browser = "UCWEB浏览器";
  129. }
  130. elseif(stripos($ua, "WAP")) {
  131. $browser = "Mobile浏览器";
  132. } else {
  133. $browser = $ua;
  134. }
  135. if ($browser == '') $browser = $ua;
  136. return $browser;
  137. }
  138. /*取得操作系统版本*/
  139. function os($ua) {
  140. $os = "";
  141. if (stripos($ua, "Googlebot")) {
  142. $os = "谷歌蜘蛛";
  143. }
  144. elseif(stripos($ua, "Baiduspider") !== false) {
  145. $os = "百度蜘蛛";
  146. }
  147. elseif(stripos($ua, "Yahoo!") !== false) {
  148. $os = "雅虎蜘蛛";
  149. }
  150. elseif(stripos($ua, "bingbot")) {
  151. $os = "必应蜘蛛";
  152. }
  153. elseif(stripos($ua, "YRSpider")) {
  154. $os = "云壤蜘蛛";
  155. }
  156. elseif(stripos($ua, "Yeti") !== false) {
  157. $os = "Naver蜘蛛";
  158. }
  159. elseif(stripos($ua, "Windows NT")) {
  160. switch (substr($ua, stripos($ua, "Windows NT") + 11, 3)) {
  161. case 5.0:
  162. $os = "Windows 2000";
  163. break;
  164. case 5.1:
  165. $os = "Windows XP";
  166. break;
  167. case 5.2:
  168. $os = "Windows 2003";
  169. break;
  170. case 6.0:
  171. $os = "Windows Vista/2008";
  172. break;
  173. case 6.1:
  174. $os = "Windows 7";
  175. break;
  176. case 6.2:
  177. $os = "Windows 8";
  178. break;
  179. default:
  180. $os = "Windows";
  181. break;
  182. }
  183. if (stripos($ua, "WOW64")) {
  184. $os.= "(X64)";
  185. } else {
  186. $os.= "(X86)";
  187. }
  188. }
  189. elseif(stripos($ua, "Android")) {
  190. $os = substr($ua, stripos($ua, "Android"), 11);
  191. }
  192. elseif(stripos($ua, "Linux")) {
  193. if (stripos($ua, "i686")) {
  194. $os = "Linux X86";
  195. } else {
  196. $os = "Linux";
  197. }
  198. if (stripos($ua, "X11")) {
  199. $os.= "(X Window)";
  200. }
  201. }
  202. elseif(stripos($ua, "Macintosh")) {
  203. $os = "Mac";
  204. }
  205. elseif(stripos($ua, "IOS")) {
  206. $os = "iOS";
  207. }
  208. elseif(stripos($ua, "ZTE")) {
  209. $os = "ZTE";
  210. }
  211. elseif(stripos($ua, "Windows 98")) {
  212. $os = "Windows 98";
  213. } else {
  214. $os = "未知系统";
  215. }
  216. return $os;
  217. }
  218. echo "当前浏览器:".browser($useragent);
  219. echo "当前操作系统:".os($useragent);
  220. ?>
复制代码


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板