$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.         ?>
复制代码
5 V6 H4 d" Y0 b" b0 I0 T. }+ K

+ A6 `# A5 S, D! r

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

' }" v. O; I" D" K2 b0 l

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

& F8 I5 [5 ], m+ B: c7 D/ ~

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

3 B2 Y. ]2 X8 o0 V* ?

) U- `% g4 y! X7 m. t8 }& i

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
% m7 b; V( T! fUser-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
* q9 W$ ~2 F" \# z) c% _$ R- E0 ^  ?6 X  N7 n
safari 5.1 – Windows& Q" ?. P! e- E$ ~
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
& U/ s. P' T5 F5 V- t& W7 o1 |. w+ V' x
IE 9.0' H/ q$ R: }( b7 v
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
1 O- w" b0 O0 I# i% P$ ^& q6 a0 Y$ _5 b# k+ ~9 m. l
IE 8.0+ h- D& v/ j3 ?  s# U; Y/ e
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
& ^4 a  k, e* q
0 g: Q6 y; o' }IE 7.0/ U3 Y/ W8 z/ i2 f3 M" |
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
& v# ?, A3 J4 d9 @' D, Y) Y
4 O' `: r0 O7 iIE 6.0
# d$ ?$ H0 D3 q1 h& ?* dUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
0 K) k# ~4 j/ h, O( ?/ {3 U  O9 J8 X+ _! @9 O9 k0 l1 u
Firefox 4.0.1 – MAC- f8 a/ q" K5 S9 i0 p
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
7 [+ o/ P5 z8 t$ `: M2 @3 D0 M4 R1 C' b- p) o  p1 P* g4 h
Firefox 4.0.1 – Windows
2 o$ X8 z& `8 e5 xUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1* M: L5 U5 b/ S) S5 t) }/ x
& K- `* ~# f$ U) E2 j' g/ t
Opera 11.11 – MAC
1 O5 A+ o( m- {2 VUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11" l; P5 m0 W" X# ?

. u: h- X! w; e; COpera 11.11 – Windows
' D8 p* k5 U' V- R4 eUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11% s; r7 R) t- J( Y
. D4 W, R$ S# `+ C/ ^
Chrome 17.0 – MAC
) \5 c9 J# A3 V/ |  {* c7 IUser-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、国产浏览器

Maxthon4 c  W, _- u8 e  }7 ^! P% Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
- h3 a  @  t! m% d9 w0 B" L; z- |$ S0 J  D8 c
TT
3 ^3 y, J+ ?% n# s9 Y% R3 w3 qUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)( s; V  R/ s0 V5 _1 B! H7 Y

; c$ C+ P) ]6 `( v0 A1 WThe World 2.x& I+ n2 {" \. p/ T3 h
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)# z# I0 E+ z( l6 C( m, }0 H6 u

% ^/ P# t; o% V  y% TThe World 3.x
) u  E3 O: Y5 X# C  H% bUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
/ q& j# O# ?( Q! M# X
) v* B0 \  u5 ^4 `4 o搜狗浏览器 1.x/ K# M* a7 t0 s: I: [. K" u
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)
% m  w% o6 C1 Z$ k4 a, z
  }9 n% u, I( k% }2 d% e360SE
/ R# V9 _( w5 _. J) RUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)& v6 l, a3 \1 U

+ `5 V5 M8 \9 L+ ?" T3 ^3 hAvant
. G3 h0 c! ]# e/ b  P+ DUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
( ~& {3 E- ~0 E. @- L0 ^) c3 ^: o- Q6 ?
Green Browser
1 w& G2 {+ \; ~9 _. l) Q7 |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone' I0 P/ z" e5 t. e* }7 @
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. j6 n6 a+ y& u5 c" T
0 x2 F! u, M; z& H
safari iOS 4.33 – iPod Touch
! ?9 D2 R& k" I3 N7 k; B/ J9 uUser-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
; \, d7 J0 w6 q" V
- x- u4 O0 ~5 ]. a0 ?# ^3 _* wsafari iOS 4.33 – iPad
( ?  v* M; S. u. W, N/ @+ ZUser-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
+ \/ a* e) t; @7 t
% P- R) e3 a. J% l2 J- _3 t( qAndroid N1: H; o* K" S  G8 K
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$ ~7 K7 ^4 s2 F" J& r0 Z

" _& H3 B0 [" X" r7 n$ PAndroid QQ For android: L, q3 x' |9 c7 W+ d! F3 t
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.19 o9 C: w1 L- S

4 o# L6 ?, l3 |Android Opera Mobile9 Z' k% \3 P* x9 b
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' s* U2 w( H9 U( w+ E* o
& n9 [! L/ M4 U; \
Android Pad Moto Xoom
( J1 b. ]5 F3 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& n+ R+ p, M0 d" c$ f9 \2 r

" O) e1 g, D7 w+ WBlackBerry
) `1 y# A0 m' {0 s: yUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+3 H4 z0 a1 C: ?8 }

1 M/ X1 O. _( a0 `WebOS HP Touchpad
+ a0 Y6 x* w2 OUser-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% ^+ b+ i/ t& J( Q; g/ r7 b

" e. {3 ?( q3 z* @. ~Nokia N97  N3 j; w" ~1 ~2 L
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  L" ~2 [' o; W! @5 c. y
. {8 y7 ^' d7 s
Windows Phone Mango
3 b1 q4 y$ }( }0 [* x2 EUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)1 k9 p# ?, J) |1 z' v5 n

/ G+ G  ^' A# Z3 G' s. e6 W! dUC标准! W+ `# G* h* L! L/ t/ l
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
& G" N8 z9 N) ?
$ |/ r' x! U' ?UCOpenwave
  E; t$ ?0 a$ n# ?$ [3 i- T' CUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
9 {2 Q1 r: p7 Y" N5 }9 K+ O8 c* l$ q' a# j3 V  @! _$ p( ^$ T
UC Opera
( `7 O5 D8 u2 ]( S, h& qUser-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
互联网安全