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

  d' a) B4 w3 K  v0 n6 Q0 f4 s


3 e3 Y% ?* Q# n" N( \' {

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

+ t, O, R% |5 |9 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.         }
复制代码

2 A& R! m/ e- A& |% r1 j' F

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

3 @" H: K, c& ^. J+ x
) h+ w2 b; z* t4 R& i( k( \1 S9 u

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC, q+ @: X! \/ k0 Z
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.508 F* m8 h) j: T! Z' n) l

/ I8 n; s" V% ]6 H# K: @safari 5.1 – Windows
. Z% D- w" e0 b: Z% q5 @, u" xUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
! m0 b" F7 V! P* I/ g9 c$ G/ D7 }; F
IE 9.0
( T' d+ D2 L3 E  y' k1 hUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;3 |' ~5 C* S+ E! k* L( Z
/ Z$ s9 p" W9 A  Y5 ~9 A6 A
IE 8.09 n' K7 y+ T( Y6 V/ T
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)( J! w# I" y: t6 a! E
$ m5 _0 |9 R  \! U* D- f
IE 7.0
+ S& ?! g- y  hUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
7 o1 s, [9 r/ p+ F& \9 s: d, G. m6 ~2 u, e
IE 6.0; _' y( a, K3 D6 p) ~) g
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)6 n8 w! Q1 P$ U) O
' c' U5 p6 U9 h
Firefox 4.0.1 – MAC. r! l0 M* P1 p+ m$ w* U- U
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.18 o: b$ s7 M5 \" o, c" j4 W

6 R" h/ F# E, ~' x1 \6 B( V% tFirefox 4.0.1 – Windows
* i' u1 T- T8 C  d+ \# WUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.10 H" [* }2 c4 [( V

( X1 W" c# N( y% h- B7 gOpera 11.11 – MAC
4 p( V6 K9 i  |0 }: U8 v8 cUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
  q* l9 }6 e% S7 c. N
1 `! ?- x4 Q+ T3 [4 Y$ L4 ^5 vOpera 11.11 – Windows4 O' i' o( `( k7 ~% z: ^8 K, W
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
: _3 b2 r  ?& C  B7 v$ n7 e- S' t' y$ H$ Q3 e: @2 P  p5 W
Chrome 17.0 – MAC9 ^$ b3 I2 F& f
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
8 ]# V/ W/ {8 P, W9 U" v# [User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
+ b7 T) s' {0 J: V' b
& o7 m6 b5 [: z/ J) }( B7 GTT  ?' ]& m. u( Y. Q, P" X3 Q$ A( k
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0): P/ t0 D% p9 r. P- s# T

% V; |- o% y4 a8 O/ bThe World 2.x. Y* [- v0 z' G, }+ D
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
& N; R5 c5 m: N/ Q! N/ ^/ \0 R; r; J8 e8 Q( `3 d) m
The World 3.x
. o) ]" S* N; {% @User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)) O4 l- l# I1 G% W8 I) b. t# u
0 }8 _: }" `; J+ a# {  x' m% c
搜狗浏览器 1.x
5 |% j/ L& }0 \& e* F) eUser-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)
3 {7 ~8 F6 P+ Y  ^5 N6 x; g7 v8 v9 L$ t3 E8 \
360SE% P2 S+ Q% J. W! ^! P
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)6 k( e8 a  r4 x
+ h, u1 Y: |: D9 b
Avant% b) U5 R! L: A2 _/ h4 s
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser): Y9 e- j# `/ T

, V' ^$ [+ v  `8 S; ?: ?/ IGreen Browser$ m. o$ J. R( h5 ^/ l- Q2 ^
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone3 e. f- u% N8 p8 k
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, n1 W6 d& A& j! N! g

$ T; c$ K( c7 J: Dsafari iOS 4.33 – iPod Touch) e$ |3 C) k9 i& I. ]
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: N) l5 S( a* x$ R3 S* f3 ^9 C7 j
5 O% [. z8 ^+ _$ l
safari iOS 4.33 – iPad
  n) J8 v% {. d$ |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
" F' z2 R4 z  \' B# ~1 v6 z5 S" }5 d7 u
Android N16 |( k( {8 v. i6 ]! H
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
. M* x" G0 p4 `. H! ^0 z' b' _) {6 y, ]$ ~
Android QQ For android0 \9 {5 V5 ]; Y/ K; Y. }& ?( W
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.13 U" m, I1 ?/ q8 ?) U' B

; ^$ f$ B# h7 G' z, i7 _Android Opera Mobile: `1 g7 X/ E. P; d. D( [
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.108 ?1 i: G8 d4 g. }
' ]6 K. P7 u. P3 [$ F# u5 z
Android Pad Moto Xoom
/ f5 w( o( i6 K& rUser-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.133 I4 a, l; V; h& V8 A5 q( G1 m
% V/ q/ x, H% n5 H
BlackBerry5 `9 }% f: v: {7 A$ s# N+ j
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+
. F" v# O" t) z# J% c9 k! W6 }" |! D. O& [  q! R2 r' C1 ~
WebOS HP Touchpad
4 o) L$ q2 j* {9 V) X/ q; r# uUser-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
# M- L; C# x0 X9 f( W
: G! a# ?7 N8 F0 @! Q  q4 f' dNokia N97
$ P4 y# h. s$ Z9 AUser-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.181241 Z% b! ]0 `, c
' x/ F* C/ l% u
Windows Phone Mango
( q: h& e; o& y% aUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
) u' O0 w8 z3 t. \. q3 I8 v2 O" j* G% ~& R5 j$ W
UC标准
/ Q) q$ s2 Y6 O" Q# T4 d: {6 d8 lUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
" ]: @2 L; z2 `& J' \! ]
9 O  V; s- `7 v0 E; c5 R; t, RUCOpenwave
. ]  v0 s. I' E7 d1 CUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
' @+ f' ?, |/ a  U2 O; Y5 z9 p9 ?; a# M' l
UC Opera6 E/ o$ o3 M/ s' D3 m1 S& Z
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
互联网安全