Board logo

标题: [其它] 分享php/asp/asp.net aspx判断百度PC端和移动端蜘蛛的源代码 [打印本页]

作者: jfx    时间: 2016-8-30 17:38     标题: 分享php/asp/asp.net aspx判断百度PC端和移动端蜘蛛的源代码

由于移动流量日趋增多,我们统计网站流量的时候,需要把移动和PC的流量分开,而遇到百度蜘蛛的时候,为了更好更细的统计,也需要把百度蜘蛛的移动端和PC端分别来统计,这对网站分析有着非常重要的意义。本文提供判断百度移动蜘蛛和百度PC蜘蛛的源代码,有php、asp、asp.net三个版本。

php版

  1. <?php
  2.         $ua=$_SERVER['HTTP_USER_AGENT'];
  3.         $ua=strtolower($ua);
  4.         if($ua!="" && strpos($ua,"baiduspider")){
  5.             if(strpos($ua,"android") || strpos($ua,"mobile")){
  6.                 echo "是百度移动UA";
  7.             }else{
  8.                 echo "是百度PCUA";
  9.             }
  10.         } else{
  11.               echo"不是baiduspider UA";
  12.         }
  13.         ?>
复制代码
0 ?3 d- I  \- D7 r

; Q: u! S0 ~, t! ~' ]/ `

asp版

  1. <%
  2.         ua=Request.ServerVariables("HTTP_USER_AGENT")
  3.         ua=LCase(ua)
  4.         if ua<>"" and InStr(ua,"baiduspider")<>0 then
  5.             if InStr(ua,"android")<>0 or InStr(ua,"mobile")<>0 then
  6.                 response.write "是百度移动 UA"
  7.             else
  8.                response.write"是百度PC UA"
  9.             end if
  10.         else
  11.             response.write "不是baiduspiderUA"
  12.         end if
  13.         %>
复制代码
( q6 t. j- E: Q1 Z( A( Z( M

asp.net版

  1. string ua = Request.ServerVariables["HTTP_USER_AGENT"];
  2.         ua=ua.ToLower ();
  3.         if(ua != "" && ua.IndexOf("baiduspider") > -1){
  4.             if (ua.IndexOf("android") > -1 || ua.IndexOf("mobile") > -1)
  5.             {
  6.                 Response .Write("是百度移动 UA");
  7.             }
  8.             else{
  9.                 Response .Write("是百度PC UA");
  10.             }
  11.         }
  12.         else{
  13.             Response .Write("不是baiduspiderUA");
  14.         }
复制代码
% m- K" S& _% x3 w" q* ~8 a

以上demo是通过ua来判断来访者是否Baiduspider,是比较普遍的方法。


  J3 Z% k; S8 n8 P; p! |. i3 q2 ^! w2 M7 s

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
' b; ^, c  F' ?" oUser-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
7 k9 S6 M4 [) m- Z$ g7 Y/ U0 |- m
safari 5.1 – Windows1 N" d- E  n; T* @" t: y; i5 d
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50* v6 F* A' h- @! f. W

4 ?0 P( x/ n/ D9 R' {& DIE 9.0
1 K+ l& m5 A+ D; j% MUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
3 m8 T1 T4 E9 }- [* F' Q, L7 p, F5 ~0 T+ N/ s
IE 8.0
7 m1 q' D) ~4 z9 C% wUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
0 c, A0 p) |+ f' k5 d& [9 M- j- X* l( P5 O2 d8 F/ d) w
IE 7.00 ^4 p9 l! ]% Z# a/ l: `( r8 B  s
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)2 y) p. D  \. d7 [+ ?% F
& y. Y1 L/ L, |9 W
IE 6.0
: Z. q0 s6 v) g7 eUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
# H+ |. L: T6 h0 W6 z1 {4 R; h# t0 v/ W, \  u
Firefox 4.0.1 – MAC
( _1 a, B6 p) X6 D: Q/ {User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
2 @. b; |: y4 e, _+ R- H
3 n- q% @3 f$ Y2 lFirefox 4.0.1 – Windows
3 j1 \$ @$ n0 S; _1 G6 T3 n7 pUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
+ f% l* l4 _# ^& ^5 z7 Z0 B$ l
8 f& l' t6 M+ _6 cOpera 11.11 – MAC5 c, V6 g1 X. _, w1 \
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11; k+ m+ K5 A* I

# g* d: p4 R+ X2 X& c7 HOpera 11.11 – Windows
  R  C, ~: a( U) ^User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
: j8 Y, T( i0 Z" X7 h  @
/ P+ d3 L4 h- x( M. MChrome 17.0 – MAC' m  \  w% A' R9 k7 I' h7 _% I
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11

2、国产浏览器

Maxthon
6 B, J# R1 ~' MUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)4 e# S! G8 O' L$ {
) h- U' c  J' L
TT, b9 \* J. a1 y4 i
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)- z" s) J/ d4 B0 D, A
" V3 Z1 j# e6 Z) q: |# v8 ]1 O
The World 2.x0 V) Z( V6 ]5 l# d! H+ V
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
% p7 N! D9 Q, a2 a& F$ {: ?
/ V6 F$ u% t5 w% z" kThe World 3.x
0 J" t$ x* z* \, ~8 r( _User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
" M3 h6 q5 [# d% P# W1 @0 y' k0 A5 l" c: e4 ~1 `1 W+ Z
搜狗浏览器 1.x( ?3 U  S& c5 U% a
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)8 n9 Q" n$ G) n9 E
& w! k# i9 C3 ?
360SE
( D& {: `7 o, b" HUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)! R  {" R% z/ A' M4 ?
% w' L; ?6 X9 O& Y. [. b
Avant
! C* x( |: ^- h8 wUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
% Q: d- b8 q, E: U0 j( B( D5 K& ~, c7 L5 i: Z
Green Browser$ D4 V% ?, f2 z5 l- p
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone( b6 C; K( ^7 G5 K4 A- L! g6 j9 C
User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5  d3 J/ p/ u) k/ f! o6 g) {( `

2 i1 |! Y# n3 \5 Hsafari iOS 4.33 – iPod Touch
$ o. }% T0 [; ZUser-Agent:Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5. c( e! d  ?* @0 T$ \& f& w: ]. B

( ~( b( Z" @* P% i" K3 msafari iOS 4.33 – iPad
+ J: e  F) Q/ b. [3 t" TUser-Agent:Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
1 g+ }+ R2 K1 w4 L, v! S* f' z) d/ ~& z' m% N/ x' t6 Z
Android N1
, C3 q* `( Y0 o: Y$ YUser-Agent: Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1& ]2 b' @; [2 }& m+ T9 P+ H& ]
; ^: p  r0 c7 M9 M$ w6 N
Android QQ For android) @, K- s- P/ @2 L0 v' z' s# Y0 _
User-Agent: MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
* G% ^) p7 [, A$ R9 _7 w" E
) w+ Z  W. |+ \* XAndroid Opera Mobile
% W/ z6 ]7 Y2 H% Q! X/ vUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
  X1 y2 ?, V8 A& S8 R  ~6 |$ T: G1 d3 ]
Android Pad Moto Xoom9 y. d4 j2 u3 G' h) E" [2 v# _
User-Agent: Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.137 D* s" s( Y' M& r+ M' P/ \

; L7 {" Y, g4 U- ^BlackBerry
- x- h; m: r( L' JUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
0 x4 _2 M5 H# Z4 @: F! ?- _! V, M; m& D, E* ~# b
WebOS HP Touchpad7 F8 [! z7 q6 @) [
User-Agent: Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.06 K, Z0 W- J# z

& n6 `0 C7 r% t* vNokia N97
+ ^" I; D" u3 k. C, }* HUser-Agent: Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.181248 B+ ~; `& \/ ^- T
7 t. j) ^5 t. S! @4 M
Windows Phone Mango8 m1 o; o' J9 f, |0 a& S: H
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)$ i# G  F2 x& X$ u" K+ x
( L' M  J7 e5 f" b1 h. P9 O  k0 S
UC标准, d& |. P  d8 I$ I% v
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
* W6 B, L* O- k  @: {- j7 ~- ]: N$ r0 A) |$ p3 u3 U* @
UCOpenwave
2 \2 Y" d) r/ f: |: s0 OUser-Agent: Openwave/ UCWEB7.0.2.37/28/999* {/ A7 V( n( G9 Z; c; D' }  v5 W* i

3 P9 T9 T# R7 w5 P3 F/ SUC Opera, \- x( [% A" f+ L8 N
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

参考: http://www.webkaka.com/tutorial/zhanzhang/2015/060421/






欢迎光临 捷飞网络论坛 (http://bbs.fjbjdd.com/) Powered by Discuz! 7.2