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

9 w! G2 [7 w1 p( I

- k! t! W+ B% J) L5 m) f$ |

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.         %>
复制代码
8 L- u  l6 V5 _' G

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& U5 j4 D2 |0 D( z  L

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

- t4 i* h. ^- Q( h3 u, M3 T5 k& |( o
" L1 m( @: ]+ s9 B1 u6 o' B! q

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
( ^/ D% {* S; @6 a3 s0 p, V2 d" XUser-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
& m9 E2 ~7 b  t, K9 M+ D1 B; T/ O& i9 c0 S6 k
safari 5.1 – Windows
0 D' P0 \1 g7 G4 |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
; R! y2 P& B6 M5 _. n5 t
$ t% F/ _' `% ^$ c% D5 k5 AIE 9.0
# v' d& _! u, |User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;: {8 o$ a) ?' H% X! N7 C

8 y/ x2 Z, k- [8 E, hIE 8.0$ j4 Q' v# b7 j4 c  _; ~- S& F0 |
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
: w' S( b* V" |8 t" j' e& D% a: I( a3 v
IE 7.0* b, A4 @# H  H, S
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
* t) E  [/ E: N1 I( X$ b. ^
1 x- j, N% K4 T  m- tIE 6.0
- s2 @- x2 I. B8 L% OUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)0 a. A" Z9 R6 N9 Q3 F9 t0 T

# l6 i7 i* ~2 q/ H5 V$ JFirefox 4.0.1 – MAC
3 o0 f0 p- C6 C( S# l: X! qUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
8 ?$ g. Y1 ?1 j& F% k3 u
% M( E2 s  f" m0 I! C4 w9 ^Firefox 4.0.1 – Windows# B% I4 R* t) v8 O: V
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.18 b) |) }! q3 `1 a( s
" B0 H) c, M. P: m! w9 o; Q! I* S
Opera 11.11 – MAC0 H1 q# e, t2 n" X5 ^- m
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11+ q2 n- |; ]# X7 V
; ~( g: ?7 W+ T4 F
Opera 11.11 – Windows# F  k7 a# n0 v% @4 e# m$ z  @) F
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11) R" W0 d* X5 j, F

8 W2 E0 @' R1 a) HChrome 17.0 – MAC% ~: c- l/ w! f& ]2 R& x- D
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- |& R  H- e9 z; w) O
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0), g1 l' M; B. Q: y3 m
  Q( r; `* y, {/ b
TT
5 T) v8 U. t; q7 x! Y( GUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
3 w; n8 I) E" t8 `" B; [; N
: w( ^# c0 l8 v! DThe World 2.x
4 u+ U2 ?( [! O* ]3 o7 z% WUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" A5 O4 }( ^% x, A3 C' t: L1 O7 i

) Z& S5 x4 K1 G: S1 TThe World 3.x
. ]% A* u' W! \$ ]# c, k; Y" vUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
( e% p8 s2 W% u! @6 i' R% G: `! R/ f# L
搜狗浏览器 1.x
9 y+ f' c9 h. R7 R3 v4 j% NUser-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)) I3 K  p/ h% V- D
/ k( K9 t* ~0 e: Y& ]
360SE4 m" Z+ N6 u) T" I
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)) _; j4 S" {3 E

/ E$ p# W+ o( J8 ]( p# tAvant* B0 f: i% M6 ~" ?% W; u
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
' c6 a; q" m9 ^. x0 }! Q) j/ ~0 `: B) n
Green Browser9 E- U8 o- d2 T$ B1 w1 s3 n# n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone( k$ m0 w. c" 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.5/ x- ^* F$ f6 |8 _8 g

( P" v' T3 N6 U& Nsafari iOS 4.33 – iPod Touch
% U2 @8 F, e0 i2 V& PUser-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.54 Q1 k& l& l* G( Z8 G& G

- s( R0 |1 h2 m* Q7 g1 gsafari iOS 4.33 – iPad6 K: j6 R, K1 |) Z
User-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# T/ M/ H: U: Z0 w7 M
# h* u6 S4 l, F; {: D3 k
Android N1) w3 R; d; H' c
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
# \% j( D9 C: i5 u8 }& j
0 W9 O6 W2 f) R) z6 W  G+ oAndroid QQ For android
: B: v# n  f7 o) NUser-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
! G8 f& L  r3 I: ?- t8 I" b5 J" p+ A& U, R; H& }
Android Opera Mobile% ?) Y8 N' H; @$ y
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10( R9 S4 d' ^0 Z1 n1 h

; S; w* r  }  P. s) i8 z7 NAndroid Pad Moto Xoom0 A# P7 j) ?0 A% Q7 l" i. }' ^; }
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$ ^4 z0 I' y1 `  Y
  A& u' Q+ y9 m% a' u$ Z+ T, Q
BlackBerry
$ _2 N8 k, \# S. PUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
' ]6 z9 A# N* ~/ R, o: D7 f) r5 f! I) L6 Q8 O2 h" Y- V" f6 p
WebOS HP Touchpad
: J4 E! `1 q1 W) cUser-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
2 F  n' e- _: n  Z5 N# e
2 ?% q; c& ?9 O9 b/ _8 oNokia N97" A& J4 V6 [9 l: W1 G
User-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
6 t* j6 d0 _: F
& d  U: n; J, gWindows Phone Mango
9 B: ]- o8 ^# P, ~User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
$ H1 Y) y5 R. W8 ^# j5 U; W) A( f5 g- k: `2 U% t
UC标准# T+ e9 D* g1 }, t# ^
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999+ M* Y; P8 a* G; @' S4 M( F
; C, P7 F8 o9 i$ d. x  f
UCOpenwave1 D" D# G9 o, q# t/ l" r
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
$ s7 h9 i# I) X3 `1 Q' I
6 S. c3 i6 j' `8 GUC Opera0 L. M& ~5 I% s& a& T( B5 A
User-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
互联网安全