$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.         ?>
复制代码
% j$ B% r& y, w. W5 \; E


/ m, {4 ~% m$ A+ w

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

$ |) l+ A% D3 u9 S# V3 A4 B

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

* I3 z6 u: T. R0 G! }$ u& [

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


7 C1 |! I& h3 ~! i, \. I$ S
. L! z4 e' `7 i/ M; V6 u- }: J

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
. B' H5 N0 W7 l8 r- y5 C6 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
0 Y- C: z- T! X' w3 {$ V
" W" N. Y% V8 o, w8 csafari 5.1 – Windows
- _# X7 k4 J; [+ Z7 D2 NUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.505 u: M. _+ X2 \5 s, U5 k3 u* M
6 V! Q) Y5 [/ h  ~3 C! E
IE 9.0
5 m3 I; B+ P- g- x3 IUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
9 `* @/ F( y  i  j5 s: g3 [" b
7 p) d! _2 U2 i$ _- b0 zIE 8.0
8 R; a5 A: g" |' j. V1 b* ]- X& kUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)# _5 @1 `! H+ r6 m- P& D) Q: q

, M1 J4 r4 m: A! Y) e2 x9 FIE 7.0
% r& x  ~( x* ]) ~User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
& Y0 z3 u% ]* m4 P* k5 y7 X  Y' L2 Z
IE 6.0
( V) M( I# \) I% _2 p" vUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)& Y* W" a: B' v$ q. `& a: A
' w( j- v, y2 @' D: |5 l
Firefox 4.0.1 – MAC, @; ?+ t( }+ ^. S6 k( k  l9 _
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
# c  \; K5 W& c& @% g1 {+ z
9 t" J% p% L. l6 C9 hFirefox 4.0.1 – Windows
2 E( U* ]( o$ x# ]User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
: I- h$ g6 o& c. H# M/ M. A& y- `1 S% {6 L3 ]- B# ]% ~
Opera 11.11 – MAC- B6 h/ _1 ^' M  Y* |8 E# L
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11  Z, A3 L0 B0 x5 e  l0 M3 \: o

! @5 x; G) t* ~0 m9 p( N2 i8 A2 n0 vOpera 11.11 – Windows& ]8 a" K$ ]( F1 ]
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11% A' e- p7 H' Y

9 k; ~/ J+ {5 fChrome 17.0 – MAC: T' P& N5 Z% ], Q, H6 G0 `  Q  E
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' h/ _' n3 _- X/ d
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)0 V6 }% E  g& [' Y
% B0 r0 P; r1 n4 @8 e. t& n/ j  h$ p
TT
# G  n3 R3 U5 F+ [: V' ~User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)8 P+ F5 e' S9 V, m: r: ^

+ n9 Q, X1 F1 M$ J* C# {The World 2.x$ R4 D. t& _, k' U4 M, d8 x6 e2 Z
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)  J% Q+ s* ~+ g1 J8 a

# U5 f9 m1 J+ d9 uThe World 3.x
6 q& @' m) u: E8 rUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)' S5 v! L; \& R/ t- @5 U# y
% N* E. q: w' W0 K! h8 ?$ }
搜狗浏览器 1.x
! ^! g$ V! E5 }  z( LUser-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)6 p( o( V4 }  \( [+ b0 `: Z

$ E4 M: y4 {' s0 h! b- S" I6 z360SE
1 H' Q; V' f9 }- u3 _% m, W7 v& a+ bUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)' k  R0 J0 v" i$ S

$ G9 K4 e! t- k: j, ?: YAvant8 U! x" P, b3 x0 ^! J
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
; A  ~3 i: x0 a5 c& ], s6 P. p# N9 e! \. A
Green Browser
, f: [' V4 F' T1 R# _" T& }& T. CUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone  r" g. A9 K  L6 y3 r( s, h
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- e; p7 y9 ]& ?, {- Z
4 k- U+ p& _8 J) L' M
safari iOS 4.33 – iPod Touch
- _4 o- O6 b9 \1 d" qUser-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: G% j& L/ n- D  S( F) Z' _
0 _. `  x# G$ D/ E- n0 E) X6 N
safari iOS 4.33 – iPad
# ~7 p; R5 h8 ?  _' OUser-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
$ \6 \3 P! h8 _# @) p, k+ `/ Q8 `* @4 g; s3 I8 d* `4 l6 E
Android N1
$ q4 [- n. [8 k- U! P- y/ bUser-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, ^+ M) ?. M+ U9 Y* O  K/ N

% y+ i0 G( j) ?+ f. CAndroid QQ For android: m* w; W& ~5 B# r4 \1 u8 {9 F& h. t. m
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! O( S; m7 x* _" a1 `

/ N$ q2 g1 H! K5 O6 [7 [Android Opera Mobile
& m% B* k" }- \- o* zUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10" w- {1 v; k. f6 f

( Z8 N( L& H/ c% {# I8 i" W. cAndroid Pad Moto Xoom$ `1 h8 t' q* a: v( Q
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
1 ~7 H- T  c; r9 Q! A4 ^' B# x/ b: F5 O& ~% a. x" q/ t) n
BlackBerry
$ u. ~2 J4 J7 ?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+
0 C) `, h+ w7 U& {' ?6 I" {  |+ F% A8 q1 n" m* P
WebOS HP Touchpad9 ^* k. H0 b6 V2 p6 W( L" i
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
) S+ @" @2 _( g0 ^2 L  _7 S: r! R3 R) p' q
Nokia N97" L0 M5 |! a7 s: O9 E
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" v6 ?" S& ]7 V! N! @! d; b+ H

) W$ M  ]- e$ m9 KWindows Phone Mango' P. a3 {5 P8 s1 Q! |' j. R
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
; y5 ]6 P+ j6 q4 R5 C+ ?* v
' x4 ]1 ?: `& vUC标准
; h* G+ K0 o5 M- f, OUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9999 X3 K6 q( u6 h3 \8 c- n, _
  x) v8 i& N+ p) b
UCOpenwave
# w; ]  S; ?; K5 q, TUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
' w7 O: ^! [7 |, \, L0 ~2 z( p4 y0 A
UC Opera
! ^% p5 `# Z/ sUser-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
互联网安全