$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.         ?>
复制代码
* E9 u6 A3 b+ O: C% c8 M. k5 e

# d6 M* h6 b8 N7 S" O7 z

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.         %>
复制代码
8 x$ V$ E1 c* D$ d

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.         }
复制代码
. m+ c; L0 h& r9 z

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


' l6 C1 ]  y- L6 g1 I& `' x2 r! o6 q8 p( N

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
; C: g1 h3 k, B5 b+ G; l1 M# 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.50+ e9 P5 X1 {2 W4 b. {7 Z
; B/ t- ?! Z! E$ \% M0 l
safari 5.1 – Windows
5 @9 P! w& @; F8 PUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50: Y  q% o" C; W, f$ w

: O  h# h; o, I" e( D4 YIE 9.0& L" e  O6 R( u8 u+ B8 d7 U
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;1 j( Z4 E3 H; K% R% F3 L

+ M: J1 N  L# r2 YIE 8.0
3 W7 U' s/ b) sUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
# c1 T, M" `+ s. [3 z) L6 m
7 w. s# w3 ]/ E9 j1 DIE 7.0% Z4 O4 b4 x# S3 y. ^% _9 e
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
8 @8 v2 E/ f' k, @
+ W8 P$ ]6 D1 JIE 6.0
  K/ I' ]/ Z8 D* t  j3 m3 bUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
: d6 y5 g1 s! A2 i+ v* w; ?" l! K0 j  B: s4 t9 A. a& ~) g
Firefox 4.0.1 – MAC
8 a+ {" f" Q- _, nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.15 o" }9 E* U( z+ v
# H& O, m& z7 |4 n: p
Firefox 4.0.1 – Windows
/ q, s8 w( t) C  IUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
# H  O4 T* S0 b5 x9 ]1 R! h1 c  D7 A& p; n9 c6 _& E5 i
Opera 11.11 – MAC
9 {2 @' y$ c2 j) N4 IUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.117 |( x$ p1 b( i; x' y: x
' m, X. O0 e" I1 |8 c5 U, ^+ y
Opera 11.11 – Windows" X; O5 j( ]# W: d9 u
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11# C* a( i+ p$ q) Y
$ v5 x4 M. U  D6 y
Chrome 17.0 – MAC  ~; R3 Q/ y- r+ ~7 _4 t
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
/ @9 S" G  G  u2 t8 a1 i. pUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
! O$ `6 w! j! S! y
! r# E" O% U7 i( B# i# D) PTT( N7 x/ p; r5 _6 P' B/ U. D! K& r& x+ `
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
+ t. n/ e" a1 T; B3 p9 h, c# i5 \* K4 R! M* r. S  j7 W
The World 2.x
; ^5 L+ ?0 g+ ]8 m0 h! }$ x8 M  oUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)/ h* e" d0 t, D/ O' S& p. B" z: u% z
- L" \$ \2 [# I, O, }% b/ d) ~+ m
The World 3.x
8 T1 [5 g0 K! \0 @, r- ~+ [4 n2 c6 AUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)& I2 a' }: f2 R# B. u

+ d: m; i: M4 q) E搜狗浏览器 1.x" ?. u% j: t6 L" ]# 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)
0 z* |4 V: j  E- s, W9 w6 e
7 @% \; Q5 m6 p9 a% @0 y. w360SE9 z: J7 b" v4 N/ L, W
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
9 M/ x4 J2 b+ n, j3 |2 j1 u+ I3 l7 m( z" a+ M6 w( K, h! `- u$ K
Avant
8 D" l/ \  E) i' m$ i3 eUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)& Y: P3 @/ C6 [# b
- M! s# N, Q6 ]6 \  F
Green Browser9 x  I" o# D; Y8 y4 R  f
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
) E4 z1 x) ]3 L8 FUser-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 r2 F8 }- ^. I0 G7 u' m- ]: q( M; ?# N* T& b" W
safari iOS 4.33 – iPod Touch: F! T+ X5 A: t  ~3 r. o( L
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
2 U, k9 x1 y/ U  x0 m
3 E7 ]9 z" V. Fsafari iOS 4.33 – iPad
& i, V- P" ^3 F0 H! ^( S0 MUser-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  ]4 P! U6 ]# F1 X$ ^

. I+ b$ n0 s+ U3 Z' p( j9 JAndroid N1# T# `: B3 ?" g
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
/ ?, V' G: F& @6 I& X6 x
% R/ m: G% j' bAndroid QQ For android
1 T6 ~: P; \' N5 B' xUser-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
* G7 R. F5 L2 Z5 J5 a- h
) r' E. Z: Z! D& Z) W% b0 {Android Opera Mobile  i6 _$ ?% G" I& T5 Y/ u
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10& V' {; F) n2 g4 Q

3 f4 R1 x4 E+ \" @+ u5 AAndroid Pad Moto Xoom! {9 }* t( t0 ^$ E3 m5 ?3 O) h
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.135 @% q0 Q0 e+ s; ^5 `- ?0 Z

/ j! I- ~6 F0 |, K: O! vBlackBerry9 {* x$ _) Z7 E
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+- P5 k6 l* z0 I: G/ s( |6 T2 @

+ F$ u* {! B% fWebOS HP Touchpad& w2 t2 ]: |7 k: [- @" t
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/ \$ O) p* o3 d0 s  V

9 n: K' f1 |; d6 ^Nokia N977 m) {' x1 M  m  N1 Q
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
. H  }3 \5 N0 Y7 v( G/ r
' X4 k1 j& }% T, ^3 s) U) N, \Windows Phone Mango/ r- V  \! Y! X$ b: ^* Q
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
/ S3 {$ N' V) U. ^9 Y, t
0 y  a9 }8 w! Y) c* KUC标准
' }1 C; A) m+ t: j  R& \& J# \User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
0 M/ p! Q9 Y# |1 i* d: g; }0 b; o4 D7 x! _+ `; a
UCOpenwave
. p5 U" G- R$ ]1 D! J' _9 fUser-Agent: Openwave/ UCWEB7.0.2.37/28/9991 K. V5 c5 M  w3 ]& E- d

, ^3 m5 _' l% z, N+ }( C  }4 TUC Opera' f, s* a- ]/ v" N7 x# R9 n2 a. C
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

参考: http://www.webkaka.com/tutorial/zhanzhang/2015/060421/

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全