$7.49 .com domain with free InstantPage Website Builder$1.99 Web Hosting   捷飞网络官方淘宝店   Godaddy 优惠码
返回列表 发帖
分享到:




[其它] 分享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.         ?>
复制代码

3 F! z8 Z' }, I2 z


; ^$ D6 c* k& p( p) s1 O$ V

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.         %>
复制代码

  ^# [9 l, p, {/ S/ b  n

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.         }
复制代码
9 j7 \1 H2 r* i

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


8 X( T! h6 h5 k$ X
5 h, ^! y% k9 z& x2 i

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
5 N; ~0 C. t9 i% BUser-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" Z6 C, w8 h% ~  S  T
$ m, L5 j$ a2 e7 Q* {
safari 5.1 – Windows  L" N# p0 @9 z9 `
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.505 m4 z( v# S* ^3 d$ A

1 y8 d- u- d  {: N4 ]4 FIE 9.0. c0 n# t" A( Q+ e5 Y
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
# [: m/ H. ?' T
: r- V+ n' V8 C+ f$ h5 wIE 8.0
4 U& P  s* w% SUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)# \0 H6 }2 o0 r/ t$ d, {) Y

9 C. y  |1 F4 t. o5 v3 j/ F+ @; ^IE 7.04 p- c$ @& S" h6 G. l
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
% }# E2 w, ^2 b7 {
9 X. V- b* `( D" z5 @  w2 E* P" oIE 6.0
  w" S2 s0 ~* l+ S" g5 z. [6 _User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
$ W1 W2 s5 _7 q; l# C
$ C/ [) T: J* k) iFirefox 4.0.1 – MAC
2 y9 e5 J: B  B# w2 M9 NUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
. n2 X0 e3 Y* g. X5 j' Y. ]4 B# S
Firefox 4.0.1 – Windows0 s, `) ^* `  w/ p8 c
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1* b9 x5 X0 h. E2 b( }/ A- u  {3 o; x) O
2 Y9 X$ N. a; T% o( A' e: z  C
Opera 11.11 – MAC/ w3 l( |7 B8 P% a
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
: V' x# P3 E, U: s8 V" }
7 _8 a* J1 Y* K4 m1 u; @& Y4 iOpera 11.11 – Windows& t$ y! c4 m( B( h7 C
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
5 X0 H- h1 ?7 i8 z* j$ \5 E' Q/ p4 S, M! g1 i/ Y& J
Chrome 17.0 – MAC
  T8 U. W* h/ q% k% u# @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% s9 ]) X0 V- R' W# p2 v
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
5 g  ~& n& q3 z6 R, K
+ F" F. ^6 O, }) @, g$ Z) nTT: N: R% ]0 v5 o3 J# Q& w# ]
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)8 _; x7 h% m5 t% _1 d2 Z

- ~0 i0 `$ _$ k1 _; |* qThe World 2.x
( L! h1 g# \' O5 G, ?User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
6 B) V& K% d! x+ m1 y( g/ E# l/ c3 e% S2 W! D" d3 Y2 w, f7 f
The World 3.x: C* C4 `, N1 d6 V* ^
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
/ V" M, g0 w6 e: I: |2 x5 P% x& F  g8 h7 T' t* ?& L
搜狗浏览器 1.x$ A, J& u/ v# C. a  c7 n
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)7 M4 G4 a+ l& L

1 O/ F+ ]8 W' \9 V# w! d360SE" `# f1 ?. k  P, ~
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)4 q! n! r+ ~, V% T  w+ B' L0 q2 f! X6 b
* A) m* N5 z, W. f% Z# H: q1 @. e
Avant
6 y2 K7 `: I7 M7 S9 Z* NUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)) a* |0 T/ M/ M* Z9 [8 r) I, K

8 m9 r9 |) O9 g; ~0 X$ o) f4 FGreen Browser
' X: v7 c7 X5 p3 EUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone' m: W4 F. k8 C- b  j
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.55 S" P) U* Y( U
$ |2 h7 P* z' u+ s; H! r
safari iOS 4.33 – iPod Touch
! }) k. l1 s& t" \4 B* |- h, [6 eUser-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- y) Q+ A/ D3 |% A( Q: u3 C: K) ~
& l5 [8 c! p- t. ?
safari iOS 4.33 – iPad
! w2 P, Z8 v% `4 HUser-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
, w+ u4 ^2 k. W$ W+ D
! X" N8 e  `3 q& u5 |Android N16 p4 g! C0 a/ u5 g& F
User-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
4 T& v: t3 V' i4 o) h/ @3 X
8 K2 D8 I9 ]  m2 uAndroid QQ For android
4 N# h9 s  E6 n0 IUser-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
5 K5 R. j0 V+ j& {# w
+ c( V5 ^" P+ m$ B9 C1 MAndroid Opera Mobile
, l" _; O1 _& [5 w1 i8 p; A6 }User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
: F- T6 n3 h, u2 f0 A) Y3 l
2 }) L! T+ }/ r  u3 rAndroid Pad Moto Xoom% h: n0 D; @8 J- Z
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.13
& d! M! I$ l1 p+ r
0 s! r, e8 Z/ D( {5 F  gBlackBerry
' h, [2 {! ?; e) F  \$ [- cUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
# l+ R* V. t4 L
2 _. d; ]5 O7 w3 ^5 X/ \* fWebOS HP Touchpad
6 A" G" z* L' O6 g3 k! D3 B& M$ `4 bUser-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.0
# s, z3 x4 H6 C* ~. R7 i% j6 ~/ [/ L, A& @7 D4 |, I0 e
Nokia N97
! B* h# j$ E! X2 D8 E9 t: 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.18124# k5 S/ s+ x! {9 ?8 S9 P$ P
8 C  f  \1 ~' W4 Q4 W" |7 r* ]
Windows Phone Mango
* D/ E5 d6 l4 |: x! S9 e! mUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)9 Y8 H) I; F' x* ]4 p8 ?% z9 S7 o
; y0 x1 R% ]( Q1 v+ U
UC标准0 t+ S5 D( w$ e7 k
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
0 _  @0 R/ d" r# R0 w1 O' `2 h; m/ L% k, \
UCOpenwave
5 Q+ S- A- c; H$ ?& Q# p6 F6 MUser-Agent: Openwave/ UCWEB7.0.2.37/28/9996 y+ j; H% v' ~; K
, X) {* w2 m3 X9 d# ?1 F
UC Opera
/ A1 m& ?( ~8 j! p4 r5 v# BUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

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

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全