$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.         ?>
复制代码
) E4 m4 t1 g. O4 c9 ?* w


3 {) v/ n* R* c8 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.         %>
复制代码
0 D2 g6 A" E% f8 ?

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

1 u6 u% L4 E+ x) R

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

9 p: l* U' ?5 q( H- a/ e1 \

- e4 \" U" S' f) \

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
: ~) Z4 C2 r9 x1 a, ]7 DUser-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.504 r* G! V1 Y# b0 Y- r0 V
3 N- [" Q3 S% J+ H, U7 |1 G  G8 D
safari 5.1 – Windows
1 e; q  h9 r- T: UUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.506 P( e# R' \! z" e& t% G

4 E7 i0 h; A# y4 \- R+ r2 AIE 9.0, p1 |4 K1 E- t  d* V! c
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
7 E/ i; |1 \' k) Z  u
; n6 ~+ v# ]( J* W, r% YIE 8.05 q1 p7 T* A2 e7 K# \/ T
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
2 U* e) i* F% N. }* N0 q
: Z+ u( x: H& D4 ~  oIE 7.00 C; W! u2 T- v0 a1 A2 j
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
: K% a, d! U' t& a
+ \& k" h4 k8 {! c! nIE 6.0
4 C5 v( [" T# ~: SUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
5 x, e$ ]5 b  d* y" H/ ~, @# \, k) P
Firefox 4.0.1 – MAC2 o5 ^6 e4 f) U9 H" O* n! j$ n
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
9 W1 X) B/ H1 i
# t" ]% k  G) n7 R1 wFirefox 4.0.1 – Windows
/ U# i) I5 @  V9 o/ r" M0 S6 ^% h' wUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1& O* L8 o$ C2 U- @/ E% z

# e. q3 P2 {2 m4 c; e, \. l: [Opera 11.11 – MAC
4 r, m7 p  a, h* |+ G$ oUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
6 X. ]- e: I6 Z6 O" [! q9 N
3 {1 e6 ]7 x# cOpera 11.11 – Windows/ l& m/ H% P2 S& {8 `8 F; c
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.118 ?  C7 a* F" i; i# S6 Z

2 U6 c# Z5 h9 Q+ k5 }$ nChrome 17.0 – MAC$ A! ?% M& C5 j( f$ s  O( \
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  I. H" ^' f6 J* s, G
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
+ ^0 N; c+ I6 h# G
1 i/ b9 y# Y4 S5 s, F0 VTT4 _3 q. h6 u) v( T! G8 _
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)0 p5 Y  a( k2 x2 ]
2 \9 O3 q( _( l& ]1 J0 V. |
The World 2.x
) u" @7 g+ u) u5 i& @& M  e# dUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)( ^; {* {) j. `& ~
: t- z6 a, D% t4 I$ F- t& C. L
The World 3.x! i0 l/ B& `0 t/ p! b
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
4 y2 n* A) X2 j6 S& U9 x6 l5 m7 j3 v4 i: y, u+ b. G2 d
搜狗浏览器 1.x7 B) K0 d+ {" \" 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)2 g8 X7 {) C& P; T. U1 J

& o) c: e9 Y% i4 @360SE0 `# d: ], A0 \+ [0 _! L/ t
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
! V& [: N! I0 J( f0 A" D
* r$ O2 J) r, x8 Y4 @- gAvant+ M: P7 ^% f/ a+ x4 h# m6 X
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)9 _- u+ }5 v3 i, m
$ p/ q4 h: ?  S9 W
Green Browser2 U. ^; k! G# u
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
7 P0 p  `8 {& G# o' [' @' K2 dUser-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
5 k! D2 f3 n' ?' I4 `  U: ^
+ Y% [3 }; T. @( [/ S; H; g; E' xsafari iOS 4.33 – iPod Touch! P3 t4 k- D4 ^
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# t! R5 g$ [# p9 j: g

  E, x7 P8 ]' Z7 s  T  T5 Isafari iOS 4.33 – iPad( Q8 h6 f0 V: X. k
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! i/ D' f; E) }; m) f' e( h

: ?+ s1 O) W) Z) R3 tAndroid N17 P" P3 A! ^1 ]( R+ O. O5 B* u: N; H
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
' |1 y9 Y+ f3 P/ s1 m7 U7 A+ S
# R8 `2 X* Q  K4 C) wAndroid QQ For android
* i. w8 [% F; Y* e) E0 RUser-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% A. ?2 f. f1 y/ U

! U4 H+ y9 m7 jAndroid Opera Mobile
7 r7 B/ l" h* c' E' OUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
5 i' x* v* u. H" o/ [$ H4 W! c1 d. u. i3 q! b+ {# ~' `1 J
Android Pad Moto Xoom
, @7 ]2 t, o8 ~# L: s# c5 i. pUser-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
! j2 }0 ?+ v; V) b
2 b! ~* Z  H) Z; pBlackBerry
* E3 G# ?; Q- p( c' K6 [" B: ^( ~* HUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+4 ]( h+ V% p" Z/ m
/ S/ r: O6 |6 j# H5 j5 K8 Y4 ^$ G
WebOS HP Touchpad
. N& S8 ?8 H" ]2 j% |/ H* IUser-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 Z( p+ c) Z( J

9 g* a! o# M! f2 p! DNokia N975 {9 J9 l6 ~, @, D
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
: j; ~9 L5 i% S; L) E' l7 v' G
9 R4 l+ @" r; p6 F2 ^1 n! ]Windows Phone Mango
) i4 Z: w0 v5 u, y3 m; [& xUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
+ x$ j" z: g8 ^2 @2 E6 f$ B: j
6 y/ Q& ]1 r; U! G  IUC标准# q  `  W7 g3 r1 E5 |
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999' G. U8 a) }1 w. j9 q, R* R
; s' A6 h$ Y1 z2 ]! F1 S
UCOpenwave% y$ H1 V# p2 [: C
User-Agent: Openwave/ UCWEB7.0.2.37/28/999* h4 ]# Q0 s# C9 q8 `( K, ?
9 @( Q0 ^3 q' `% U  B% j( E
UC Opera
# D) ^) e: f  h7 E" S  WUser-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
互联网安全