Home > Backend Development > PHP Tutorial > Obtain visitor browser and operating system

Obtain visitor browser and operating system

WBOY
Release: 2016-07-25 08:49:14
Original
1118 people have browsed it
Obtain visitor browser and operating system
  1. $useragent=$useragent=$_SERVER['HTTP_USER_AGENT'];
  2. /*Get the client browser version*/
  3. function browser($ua) {
  4. if (stripos($ ua, "Googlebot")) {
  5. $browser = "Google Spider";
  6. }
  7. elseif(stripos($ua, "Baiduspider") !== false) {
  8. $browser = "Baiduspider";
  9. }
  10. elseif (stripos($ua, "Yahoo!") !== false) {
  11. $browser = "Yahoo Spider";
  12. }
  13. elseif(stripos($ua, "bingbot")) {
  14. $browser = "Bingbot" ";
  15. }
  16. elseif(stripos($ua, "YRSpider")) {
  17. $browser = "YRSpider";
  18. }
  19. elseif(stripos($ua, "Yeti") !== false) {
  20. $ browser = "Naver Spider";
  21. }
  22. elseif(stripos($ua, "Maxthon")) {
  23. if (stripos($ua, "AppleWebKit")) {
  24. $browser = "Maxthon Browser (Extreme Speed ​​Mode)" ;
  25. }
  26. elseif(stripos($ua, "Trident")) {
  27. $browser = "訨游 browser (compatibility mode)";
  28. }
  29. elseif(stripos($ua, "MAXTHON 2.0")) {
  30. $ browser = "欧游 browser 2.0";
  31. }
  32. }
  33. elseif(stripos($ua, "Firefox")) {
  34. $browser = "Firefox 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 = "Baidu Browser (Compatibility Mode)";
  42. }
  43. elseif(stripos($ua, "AppleWebKit")) {
  44. $browser = "Baidu Browser (Extreme Speed ​​Mode)";
  45. }
  46. }
  47. elseif(stripos($ua, "Ruibin")) {
  48. $browser = "Ruibin";
  49. }
  50. elseif(stripos($ua, "qihu theworld")) {
  51. if (stripos($ ua, "Trident")) {
  52. $browser = "World Window Browser";
  53. }
  54. elseif(stripos($ua, "AppleWebKit")) {
  55. $browser = "World Window Browser (Extreme Speed ​​Mode) ";
  56. }
  57. }
  58. elseif(stripos($ua, "MetaSr")) {
  59. if (stripos($ua, "Trident")) {
  60. $browser = "Sogou High-speed Browser (Compatibility Mode)";
  61. }
  62. elseif(stripos($ua, "AppleWebKit")) {
  63. $browser = "Sogou High-speed Browser (Extreme Speed ​​Mode)";
  64. }
  65. }
  66. elseif(stripos($ua, "LBBROWSER")) {
  67. if (stripos($ua, "Trident")) {
  68. $browser = "Cheetah Browser (compatibility mode)";
  69. }
  70. elseif(stripos($ua, "AppleWebKit")) {
  71. $browser = "Cheetah Browser (Extreme speed mode)";
  72. }
  73. }
  74. elseif(stripos($ua, "YLMFBR")) {
  75. $browser = "115 browser";
  76. }
  77. elseif(stripos($ua, "QQBrowser")) {
  78. if (stripos($ua, "Trident")) {
  79. $browser = "QQ Browser (compatibility mode)";
  80. }
  81. elseif(stripos($ua, "AppleWebKit")) {
  82. $browser = "QQ Browser (speed mode)";
  83. }
  84. }
  85. elseif(stripos($ua, "TencentTraveler")) {
  86. $browser = "Tencent TT Browser";
  87. }
  88. elseif(stripos($ua, "TaoBrowser" )) {
  89. if (stripos($ua, "Trident")) {
  90. $browser = "Taobao Browser (compatibility mode)";
  91. }
  92. elseif(stripos($ua, "AppleWebkit")) {
  93. $browser = "Taobao Browser (Extreme Speed ​​Mode)";
  94. }
  95. }
  96. elseif(stripos($ua, "CoolNovo")) {
  97. $browser = "Maple Browser";
  98. }
  99. elseif(stripos($ua, "SaaYaa")) {
  100. $browser = "Strip Browser";
  101. }
  102. elseif(stripos($ua, "360SE")) {
  103. $browser = "360 Safe Browser";
  104. }
  105. elseif(stripos ($ua, "360EE")) {
  106. if (stripos($ua, "Trident")) {
  107. $browser = "360 Extreme Browser (compatibility mode)";
  108. }
  109. elseif(stripos($ua, " AppleWebkit")) {
  110. $browser = "360 Extreme Browser (Extreme Speed ​​Mode)";
  111. }
  112. }
  113. elseif(stripos($ua, "Konqueror")) {
  114. $browser = "Konqueror";
  115. }
  116. elseif (stripos($ua, "Chrome")) {
  117. $browser = "Google Chrome";
  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 Browser";
  129. }
  130. elseif(stripos($ua, "WAP")) {
  131. $browser = "Mobile browser";
  132. } else {
  133. $browser = $ua;
  134. }
  135. if ($browser == '') $browser = $ua;
  136. return $browser;
  137. }
  138. /*Get operating system version*/
  139. function os($ua) {
  140. $os = "";
  141. if ( stripos($ua, "Googlebot")) {
  142. $os = "Google Spider";
  143. }
  144. elseif(stripos($ua, "Baiduspider") !== false) {
  145. $os = "Baiduspider";
  146. }
  147. elseif(stripos($ua, "Yahoo!") !== false) {
  148. $os = "Yahoo Spider";
  149. }
  150. elseif(stripos($ua, "bingbot")) {
  151. $os = " Bing Spider";
  152. }
  153. elseif(stripos($ua, "YRSpider")) {
  154. $os = "YRSpider";
  155. }
  156. elseif(stripos($ua, "Yeti") !== false) {
  157. $os = "Naver Spider";
  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 = "Unknown System";
  215. }
  216. return $ os;
  217. }
  218. echo "Current browser:".browser($useragent);
  219. echo "Current operating system:".os($useragent);
  220. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template