首頁 >後端開發 >php教程 >取得訪客瀏覽器和作業系統

取得訪客瀏覽器和作業系統

WBOY
WBOY原創
2016-07-25 08:49:141130瀏覽
複製程式碼
取得訪客瀏覽器和作業系統
  1. $useragent=$useragent=$_SERVER['HTTP_USER_AGENT'];
  2. /*取得客戶端瀏覽器版本/
  3. function browser($ua) {
  4. if (stripos($ua, "Googlebot")) {
  5. $browser = "Google蜘蛛";
  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, "Firefpos($ua ")) {
  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. elseif(stripos($ua, "360SE")) {
  104. $browser = "360安全瀏覽器";
  105. }
  106. elseif(stripos($ua, "360EE")) {
  107. if (stripos($ua, "Trident")) {
  108. $browser = "360極速瀏覽器(相容模式)";
  109. }
  110. elseif(stripos($ua, "AppleWebkit")) {
  111. $browser = "360極速瀏覽器(極速模式)" ;
  112. }
  113. }
  114. elseif(stripos($ua, "Konqueror")) {
  115. $browser = "Konqueror";
  116. }
  117. elseif(stripos($ua, "stripos($ua, " Chrome")) {
  118. $browser = "Google瀏覽器";
  119. }
  120. elseif(stripos($ua, "Safari")) {
  121. $browser = "Safari";
  122. }
  123. elseif(stripos($ua, "MSIE")) {
  124. $ver = explode(";", substr($ua, stripos($ua, "MSIE") 5, 4));
  125. $ver = $ver[0];
  126. $browser = "IE ".$ver;
  127. }
  128. elseif(stripos($ua, "UCWEB")) {
  129. $browser = "UCWEB瀏覽器";
  130. }
  131. elseif(stripos($ua, "WAP")) {
  132. $browser = "Mobile瀏覽器";
  133. } else {
  134. $browser = $ua; }
  135. if ($browser == '') $browser = $ua;
  136. return $browser;
  137. }
  138. /*取得作業系統版本*/
  139. function os($ua) {
  140. $os = "";
  141. if (stripos($ua, "Googlebot")) {
  142. $os = "Google蜘蛛";
  143. }
  144. elseif(stripos($ua, "Baiduspider") !== false) {
  145. $os = "百度蜘蛛";
  146. }
  147. elseif(stripos($ua, "Yahoo!") !== false) {
  148. $ os = "Yahoo蜘蛛";
  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. ?>
複製程式碼
複製程式碼


複製程式碼複製程式碼複製程式碼複製程式碼複製程式碼複製程式碼
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn