$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.         ?>
复制代码
. S5 \3 ]. |3 L/ I

' }2 o! ]0 ~( N2 I" m# o

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.         %>
复制代码
; r7 e$ e& E; P; c  L

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

3 E# i$ |2 q1 C) p

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


3 n5 q8 i* v. e! A% b% L7 m, a5 N# L- A

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
. M+ z. `* a# I6 zUser-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/ ]6 y& a' k  @1 C/ H, O# V

# d6 c! ~& m8 U8 T1 isafari 5.1 – Windows
  a. l8 ^: N" d, U9 f9 x" M; a1 [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  e9 c9 F+ G4 e& i7 j+ \7 j
+ S& o3 z9 `0 A
IE 9.01 o5 l: D8 C$ }6 d9 |
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
- I/ A# z; d+ B0 o' Q: C$ C' M
0 i+ `# z- q3 j# nIE 8.0% L. }% Q% v9 R) O7 x1 ~, I2 a) _
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)0 {" ?! O7 s, N* x) U' k
2 Z. }& w6 a4 H* M0 o( m
IE 7.0/ i' l6 I: @  _, d
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
5 ?7 Q2 \+ X1 Z
( W4 ?0 s. }- x% i9 z3 c' u/ GIE 6.0
# ]8 G2 W: f5 T, y2 a3 @& S4 SUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1), ~* q' o$ \4 O

3 V. t% ~. A( R. x1 M5 E8 M9 e4 h, D$ `Firefox 4.0.1 – MAC
: q9 t, y% ~/ ^# aUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
( @7 _4 O) F+ W
! f# f' U# P& j% g; qFirefox 4.0.1 – Windows
9 W9 o7 A$ \3 O* DUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
) x% F. E' ?% R+ `/ x
4 Z% E* _, |! p/ k$ V( `Opera 11.11 – MAC
, P; C* O. H( m2 h. c4 M+ W6 jUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
6 p1 d7 Q7 }* m, _8 U/ }+ s7 _/ T
. ]1 F% W% _3 F5 nOpera 11.11 – Windows* P3 g" X# p2 p( f% g. O# H5 r, K
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
7 \6 i( U7 V. Y' v. Z8 X' U
. j9 T5 m8 ]. o" u' @" M, fChrome 17.0 – MAC
# z$ U* S; z# l: z  @( o( |4 @, AUser-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、国产浏览器

Maxthon1 X# f9 Y, x: K8 d2 ?) I! y
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
/ c+ q  N9 `' W; e. [, Z
& s, b) R  c* ~TT, x* x3 A( ?3 b7 ?# h; i
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)  }" @" e& @; o: X
3 H* x3 e0 o4 [( r4 {  d# V  I: o8 _# A
The World 2.x% v! }7 ^/ C! E0 C0 }
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)& i. j8 R) v: w$ T7 M0 g7 ^
, i) o6 b0 i! S! B% G6 M
The World 3.x8 D: ~: k: L2 A, g
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)3 f/ S% N8 v; }' J4 F. }
9 \, @7 P% L& z
搜狗浏览器 1.x
3 w( Y# L# \$ H3 D, H. ZUser-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)
3 M# S8 c( D9 w8 k0 N7 Y
: B, b$ k0 s& d5 c0 `0 g360SE
- j9 P8 ^3 {" m( C8 W+ @% }1 jUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
6 j5 P% b) G6 m4 F6 W9 Y- K# h' |/ _1 ^& I
Avant
# B$ t4 {$ A' }) D" u$ ]2 ^! kUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)4 N9 _8 [! ?3 s  J2 _8 w  d

& S; U5 b' U; y: E* P2 Z) M6 CGreen Browser
# i9 z2 j# X6 g6 X' E& U0 `/ xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone; S- y# q; ?3 H3 |2 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
  A6 n! }, l& P& b6 ~% ^
) q' u/ }5 y/ S5 M- D" Bsafari iOS 4.33 – iPod Touch: L6 o: C6 p8 b) E* q) K9 M* A3 m
User-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
! Y8 t$ Q% z8 _# y9 }2 t. L. _* W2 z' W9 Y( s/ F( e. Y) C  P
safari iOS 4.33 – iPad
" ~0 E1 [7 F+ n$ ?3 a3 L/ M" \' \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.56 X- Q  n+ e1 `* c5 V& ]6 I2 |

3 z, H7 Q9 D& x/ B- b" f' ~$ rAndroid N1
# j: [1 `: Q8 H! ~4 O. |: X1 D; GUser-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* Z2 K' b. F( t( Z4 i/ L* d

& j, M* E: Y' [6 Q' b! `Android QQ For android$ z! n  l+ f% r( q2 m$ ^
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
/ i9 l8 P6 @& J. J
' Y5 g* J  L# d1 HAndroid Opera Mobile, L5 G' F0 [* V' x2 q2 S6 }. ~
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.102 K) M6 ]. T8 }$ X5 G# }3 ?
" M+ K% W2 h3 X9 E3 P4 T9 P$ x# p( ~9 I
Android Pad Moto Xoom
: \1 D1 d* d$ G- C3 g/ k) H$ mUser-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) \$ r; \5 _. Y2 A$ T
( ?+ |# y( ?  A  ?
BlackBerry. D  _% f/ o  A! S( j4 v+ x" V
User-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
3 l. y4 k9 e8 c' M6 d- \6 p- h' @, C. Z! T1 P2 e2 F8 B
WebOS HP Touchpad  i* y: U) L* Q4 p! W
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.0
/ r7 O  N6 v7 c& h& f- O% L! A1 @
, F  V& O, a1 k8 u7 Y. pNokia N970 \0 E: g4 V) l9 L1 v& k
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.181245 Z) T) ?. D8 K5 Z1 B
! W1 t  Y: Z* x5 Q
Windows Phone Mango
8 _& ^+ b* k' I% ?5 c( q6 JUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)7 `$ R9 ?5 L2 l" ~" r5 a, f

: f: f; A, G3 JUC标准2 o+ Y- B! k' c. y# Z. y
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999. U8 a4 R2 ?3 @0 a* h% r! C

, y4 z( x7 F1 {1 rUCOpenwave1 n$ j0 H9 D" i# m+ ~8 k
User-Agent: Openwave/ UCWEB7.0.2.37/28/999! I$ E2 s2 h& V& P6 B
4 }2 o+ a, J  F
UC Opera" z4 O- ^% h9 Z% u3 l" z0 K
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
互联网安全