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

/ W# S3 e  a! z2 _: m" W


$ f5 ]  t( O3 \

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

, O2 V4 [0 S) w1 z8 ?+ V$ U

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 Z- _% j# H- o

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


4 E4 Y& f3 E. ?6 G( ^! W2 a$ e( V( j  o* a# }/ e

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC8 a" |% I! b3 }
User-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
" d- p/ J1 L: d- }. m. U6 ?4 P6 ]: R# c8 Y) Z6 f' @
safari 5.1 – Windows
9 Q4 w8 ^/ m9 N5 T* r4 M+ ]% MUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50$ z$ t. i: f" i& f# G. P0 @  w
1 B2 N9 D7 H5 ?6 W/ L- n1 `4 v* J$ Y
IE 9.0
3 P6 U! a: y7 S# e9 A8 xUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
. l. a; X3 a0 D8 j7 {% l  W1 Y& Q
, e5 \. {0 }) @1 R$ GIE 8.0
1 M9 V; u- C0 H; _6 QUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)9 }8 e2 d: g9 P6 C) R* `& a* l& ~1 r

" _% x7 D* g" \3 j/ a' IIE 7.00 Z) q& K- ]* P( V1 u' ^
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
$ ^! p: w4 o  J4 _. k2 e& Y' ?8 S
: Y# v2 {! o6 ]7 N; yIE 6.0
$ N+ U/ e" ?5 y3 a! G& GUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
- x/ g! N0 n. b4 c% g6 L
) i, X+ a) d. M0 s7 EFirefox 4.0.1 – MAC' P2 N$ J. S, g( ?
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1; r) X) i5 ~3 O
  r& ^6 K# r7 }4 L* @4 g) Z- ^2 C
Firefox 4.0.1 – Windows
# M6 R% y# B5 W, O9 z; XUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
) G: v9 Y# r/ }
  f7 w6 f9 \/ w! iOpera 11.11 – MAC
* G. r9 G' o) A  z1 ^: }9 kUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
; q4 ]( ?( W6 M+ D) t; k, Q, U
% M8 y7 K0 Z) N, fOpera 11.11 – Windows
  }  ?7 o$ e4 g* [& Y7 j5 RUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11- F7 N5 H- c. P; T# K. Z
: q7 g/ d/ N/ U2 T9 Q
Chrome 17.0 – MAC
" \$ I* g- z" I' ?! 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、国产浏览器

Maxthon
/ {/ T! }4 R. _6 A5 UUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0), l8 S6 |8 |/ X  U) A

' E) B/ v" U5 }  @7 C# l: u, lTT8 Y' ]+ d% O5 {4 ?
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0), ]9 T1 w" M( h9 ~1 u! T

! p' C' X7 o( K. s/ W% v9 wThe World 2.x
2 \' W2 c" A7 E0 L  CUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
/ K4 r/ U" n& Q1 B! D, l0 h( U5 N" P  J! y* d' J6 `: a
The World 3.x8 T) y: J/ d' i( U0 u9 r, W; ?
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
7 B. r7 T$ j( z, [* y7 j6 g' J8 B/ X9 v" D- \) q+ x
搜狗浏览器 1.x
2 x' o( H! G: J7 h: h; A3 }+ `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)
! s# d8 ^2 v6 @6 {# `8 B$ Q, }
) `/ Z; u/ _5 V3 o% B6 @% H) G360SE
, O' c" L% |; h' C+ T' JUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
* U' u6 n8 I+ b& u7 m5 {: Q" s9 i/ @- @/ F" z& _
Avant% D/ }! T* \% _8 C- _
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
* c# e: r! m/ |- C3 \  O2 n7 M
: o% d( K6 Y9 X, o' c/ ZGreen Browser  ]: v2 ^; L; h9 e7 d! b' b
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone* ?5 V; y' ~1 Y$ `
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& i0 h9 i' T# J7 O) R! r

& j! \0 d8 d, A7 n/ C5 U4 Qsafari iOS 4.33 – iPod Touch
) b& Z! G4 O4 ]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; [1 n) }) `4 U5 |; k& Z
, S5 ]4 _) ~* @! \" D1 J2 l8 ~
safari iOS 4.33 – iPad
8 p6 w3 K/ B, T. w& _/ G  `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
2 ^) T, k7 ~) o4 @  r8 {5 O4 U- v5 O& |" g0 `' k' E6 X2 I6 A3 G
Android N1
: B; l- d! `# b: B0 m2 z/ R) V: SUser-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' l5 A8 U# Z! D! \8 c' A, |2 t

& a. u2 V5 x8 ~& zAndroid QQ For android) c1 g" \2 E9 ~/ u) t' 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.15 J; V  c# B3 s7 r
7 A: Z/ X( ^* n6 z8 z& I
Android Opera Mobile
$ @, m" C7 [0 j7 JUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10. J7 n' o# y0 p- }

  _; N0 Z$ ~& x( m) BAndroid Pad Moto Xoom1 g# B7 ]; ?* k4 r$ t
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( d1 u9 Q% l! P4 p* |- y
4 o% G: @7 H/ x! u% Q4 N
BlackBerry
3 a4 P/ \) C0 K" `2 q' TUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
: q$ `9 C, p+ z" T# n1 k3 O$ ]
" k5 V5 [" `) r. }4 V$ t3 @WebOS HP Touchpad
* i6 C9 u+ I$ Y* d0 p* sUser-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
& ?' N4 H- R; G" ?5 ~/ ?+ ?/ V7 o" M, [2 b$ u" ]
Nokia N970 j1 H* v5 e4 m. |: }6 }( M2 X
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
$ e! h' A! C2 O+ P" t1 Q# V) v( a/ b; Y- [
Windows Phone Mango
# O. s9 Y9 K' j1 WUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan), k. ~/ e( P8 I; u- @1 c* F! L

0 I, `* ^" {9 I8 Z/ N1 F7 `UC标准
& |6 b/ W2 z- B$ TUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
+ i! `, v* R& N( d) O; t
: J4 s0 ^# R3 o+ l: jUCOpenwave, N6 M- |: C. n" G) s9 Q
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
. Y9 F! X9 @- {" L( y( U4 p% n; A- ~2 t' u
UC Opera
* y; G$ f  r3 {, |! 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
互联网安全