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

+ b, W5 N* A- m% P' [" @

$ }9 O* u8 F1 l+ j" G7 ~' \0 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.         %>
复制代码

9 r+ @; o' q( e

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 }7 B4 h$ R! {5 F

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


# H" e' l! p  {% i4 L$ F
; ~% ^, p% I  z8 l- r+ f' H: s

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
/ g( q3 L: ?( e! b6 p' KUser-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. T' Z, @$ V+ M% o( d1 \& D. A7 u
6 W+ M* @5 o: ^9 n7 Q; A7 r
safari 5.1 – Windows; ~& H$ j8 |/ E( W( f
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 V4 J3 c  m/ A# S" O
4 M- i# _, I; b6 W0 a
IE 9.07 Y1 J* Q8 o( Y
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
! e1 W% U- a1 V9 D$ x5 c) }, s
# D( d5 [3 ~; M) UIE 8.0
3 X, T6 X% {9 J  YUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)& e9 J- B* V8 r5 F

1 r) b4 j! q' t. hIE 7.00 ^) y. n% n/ u7 a( f3 }( D6 C
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
9 t( h0 e4 S# Y4 C0 X5 k" G/ D
( A5 y# B2 \7 {+ ?IE 6.0
6 ~  b8 z* A5 F5 o- Z  RUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
& l$ X- ^; D( j  T  p( `
  w# ?7 i0 e! k- ?/ T, GFirefox 4.0.1 – MAC
, g" f2 g% p+ D3 m* Z) y7 DUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.17 g, n5 Z" F' ]6 o' H3 e. z( Q" ?

0 a/ `: q7 e* ~3 S4 s# W. v, n/ n. hFirefox 4.0.1 – Windows8 r* I, E5 p1 N1 T! r4 |+ t
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
+ R( a9 t& O+ m6 |6 ?7 a) t8 f
: }, N& f( q1 }) ?/ }6 S6 A0 G# h- bOpera 11.11 – MAC: P3 h+ Y: ^. e0 R2 t( `
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
4 W/ K5 H5 n7 G" E, H) k: J9 U2 ~( s0 _( [8 b. u
Opera 11.11 – Windows
; R$ D8 {% n. ]$ Z% kUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11# O' E9 V5 w+ ~/ c$ q& ?  x

9 l( G8 Q; U& H, p8 R0 p1 U; f5 SChrome 17.0 – MAC
2 ~3 D. L! N) tUser-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、国产浏览器

Maxthon5 ]% n+ w. F- {+ u
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)% k6 S0 s7 r* j- W& }$ i; o
% T' ^3 d2 T; k! r/ J* d6 x
TT
0 ~  `9 J* A$ A7 z; PUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
# p  O1 t9 ?+ a
3 O% u- x6 e% [The World 2.x
7 y* r% c; W  R  {3 T) D/ V# eUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)& s$ E/ W* j0 [1 Q6 m- t8 L
3 k- v: N! _, A& j: U) u  y: l
The World 3.x  u8 {9 i7 [7 x9 u
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)6 L+ y' a8 r" T/ o

9 ?4 q5 q/ W& w9 h搜狗浏览器 1.x' A" K1 K8 ^: ?
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)
. a" E- A4 N  t+ [: G2 T/ o9 d1 |$ B' o9 v/ I, I
360SE
, w5 R8 z3 B5 N  ^User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
! F% ~. d$ z# \* o1 P
7 C6 D: n5 D+ i3 a7 E' }8 JAvant
  c, F# o6 M" F5 |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
: k# R5 Y4 e: W$ {: \! z- X" E
( u4 L( p  k* U  XGreen Browser" d' l8 P9 H5 o: K
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone% u' i- J5 H* s5 N8 f
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
( V$ ]* O3 k2 [- S, v% W4 q9 q# W7 r' M- h0 T
safari iOS 4.33 – iPod Touch2 c6 d# {$ T7 R, S) f2 g, k9 I3 B! 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
3 X' l& @. n3 e% n/ R& h
( j" Y3 I$ ^4 S( ksafari iOS 4.33 – iPad) T7 q: a4 I; S* F# T- n
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
7 h) _) t: ?4 m( C
7 H2 r2 F2 P5 s) dAndroid N1
% g" ?+ }8 \% k/ [: q% {# w. }: kUser-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$ g' V8 f% y( J8 t5 L5 X/ Q
$ m5 i' [  }8 n* U8 M, R7 T
Android QQ For android
/ n/ r4 W" k2 g8 F, _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" u* `  C' ]  x1 k7 x3 d

( y' k3 L1 n8 h) ^Android Opera Mobile$ s9 [! [1 m6 k
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
. D- D+ O7 Z8 Q# P, D5 X) _, W6 r6 L; W7 u- ~. g
Android Pad Moto Xoom
1 A' R0 X( Y/ `6 G! 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
8 j. d$ V6 g! Z; `) c# }/ ~. T& R# W8 g
7 C8 d$ L4 M2 j0 W4 RBlackBerry
2 ~# l1 J% O% m( y: ^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+
8 Q' P$ ?1 p1 u) S7 }/ \5 e/ ?3 I( |& ]3 j- R2 u2 c2 D
WebOS HP Touchpad  i: Z" _3 u! b" }! G1 c
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.00 s2 Z3 W+ j! j: E

0 x) v+ _9 x9 RNokia N973 a# |9 r* G. R7 S' O6 ^
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.181246 p- E0 u4 v) N" \0 p1 S

1 p8 X  ~6 e  d$ p$ R5 f  nWindows Phone Mango
+ q7 j7 M5 F6 ~* {, q$ P# R5 B) oUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
, O$ s: {/ U$ C" S, N, a' O. N0 g; D) {
UC标准
/ p! R' t: e; H& O  o3 EUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999: r9 @7 M9 z) z; N

8 E/ N: j/ a! ?8 m  V# \# f$ j& ~UCOpenwave& H- h" @+ x. L3 \0 V0 k
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
1 n* t9 W$ p2 v2 N0 I0 b9 e" K" j. G" C+ L( C
UC Opera
! w: L. M4 @  D: P  ?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
互联网安全