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

& B1 {4 L) M4 s; @, K% E

3 \  Z( `" ?7 ?) L5 Q

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.         %>
复制代码
; f$ `, G% G, \5 A" V

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

+ S+ O2 w: W. d( q, i- }7 p

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

. X- y5 I: [* O: u: n7 V, H. Y4 u

4 _) H. p+ Q- s5 u: S. _

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
9 S* u: u4 {) E8 b) y  \  A+ WUser-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: W( Q; G- V8 E5 U

$ y9 s- w$ K* ~2 V" K4 dsafari 5.1 – Windows8 d. e' X& [4 c$ d* d( ]
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# p$ `, _, G' u1 y0 t1 E* X" q% ^, `
/ q. ]2 Z; W- P  u6 x* F0 |8 L
IE 9.0
7 y4 Z3 \6 U  n" ]User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;0 v! Q: a' E* I3 n
6 f( X( H( H& Y) V/ c9 G
IE 8.0
" [% ^. O, U/ \User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
. {, K2 P* ~' l* }- T" J) j! Y% a7 c% {- N% {/ ^( B- r
IE 7.0: z! v4 r; o! J' e; u, y
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
  v  O) ~" x+ ^3 t3 s5 Q; s
$ I- ~1 g& Y6 M% b2 G- mIE 6.0
8 G9 h5 s4 p. d9 q4 AUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
* j/ ]2 x) X4 T+ Y8 z% z* f1 Q% R' ]0 ]' @. a5 M4 [# k" ~
Firefox 4.0.1 – MAC6 L- B# T# }4 f% X
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1  l7 I' c3 Q0 C3 @
' D1 B: K% K7 N; m3 @% b
Firefox 4.0.1 – Windows. i2 M: m8 p7 ~* `
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.12 }" c! W- P7 w  g# g
1 U4 Z% X+ \2 X( h" H7 ^
Opera 11.11 – MAC
! D! i0 Q: E& J1 F+ W* [User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11- \! w$ z6 T4 |. ^; o# m  [+ l' V
2 z& _; `1 `: {5 f0 W
Opera 11.11 – Windows( c! G* }: c" f9 A- t6 D
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
1 M/ f$ v% H6 H  Q( E" r" b, H+ u" U7 c' Y9 n
Chrome 17.0 – MAC+ _  A# z9 D7 e; v! 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、国产浏览器

Maxthon3 s; W! c9 s( \/ Z2 N/ G# k& \, i
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
9 M; |  S- X$ X! n
# W2 F/ o: l" d& M" f" m" [. A8 KTT5 H3 W  s' @$ E9 A- \: Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)7 O8 m9 s: Q- h- [
' i1 K0 g( a! J
The World 2.x
# P5 M) H* @& N* M+ nUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)  Q' F9 N6 ?* x/ m% U9 z7 y4 F; J

# p+ H8 c# ]( m: IThe World 3.x
6 c+ J) K5 E5 e6 cUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)4 Q( _0 m7 H& z4 o9 c. a, r

0 Y0 N$ b: x: }6 X; Y- m/ p搜狗浏览器 1.x& k/ H, i4 }) a; I
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)0 g  h. t: s/ k+ o
# T+ g3 s3 z+ \
360SE
1 d' [# c2 E4 s/ z. DUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
" V6 a% p; l& T7 p8 @( [7 [* ^$ |! |0 o6 \2 U7 O: W
Avant! x/ j4 m, x/ O# h$ {. e
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
9 v2 u) ?9 M4 @: {
0 v# @8 Z) s, b. K4 C5 N3 u! QGreen Browser
# |1 ~2 F& U% I6 H! p# {$ t, xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone4 v: W' m0 `+ C: T
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
9 o# ^$ b  T0 r, ?/ o0 P# @. A7 X
- \7 w/ ~- O2 j# z- Asafari iOS 4.33 – iPod Touch
7 M  ?4 @0 ^6 e/ j0 a( Q% h1 [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/ V: D$ I8 }8 u$ a- A, _7 E
/ s5 E: ]) Q; @! N9 d2 ~8 e
safari iOS 4.33 – iPad
/ j5 U6 S( @' Y7 W# U7 d5 k3 V# {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 B8 d% K" T+ S. B9 w- x7 n1 ^$ m6 i9 z8 D9 l7 U0 R
Android N1
3 ?8 M" G3 }' 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
% T' r, ^( x) }+ P0 y/ x/ w# Y0 J' m7 r, w* f
Android QQ For android5 w9 U  z7 [2 B( I/ z7 M8 w4 a
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
+ [1 ^8 l3 u& U
; f* {, r  n* Q6 WAndroid Opera Mobile8 O0 b8 @+ Q' t
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10$ x5 ^' P' h$ n. [

! C- N8 g, Y5 j1 TAndroid Pad Moto Xoom
7 n. U& ^% `$ g2 D! J; P# |* b6 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
# A& v7 I2 x7 P: n: j* i: S" g9 Z
) ?1 M6 i9 u/ m; {$ M+ yBlackBerry1 o" H! Z' [0 a& K: _" m; x
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+: o) ^+ X) {! f9 P; o+ h

4 s4 k1 @2 u0 L9 y+ bWebOS HP Touchpad
* b: f# M& g' W) YUser-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
; }4 Q6 w- A. \* j
! ^/ n: P3 ?  T/ UNokia N97. I1 H" Z" s6 v; Q% y
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$ m- U- g4 D. L* j, @
0 ^. y. t1 y) x: n/ y. C
Windows Phone Mango- q* e& S9 }. S% g
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
4 h+ o) W. y/ h- D! G& ]$ E, t& Z6 ~# T* _+ i
UC标准
- A7 _9 F- b" y, ^( o+ w7 pUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
0 \3 Y/ Z1 _* v5 d4 I2 H: V) T- `7 ]3 e& [% ^
UCOpenwave
( p( g2 N% i7 s! j* o7 `User-Agent: Openwave/ UCWEB7.0.2.37/28/9998 c  X/ ]% V7 J* L7 S3 S7 D

6 o3 x! V3 u) ~3 V. A4 J! J8 a# rUC Opera
  \) u- {' e. U8 ~8 ?! ?$ A7 @9 H: hUser-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
互联网安全