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

: R3 u# s2 ?* q( G* V: E

, h- T! t- ~" c7 [. ^; |* O

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

2 x$ J: j' ^' y2 G

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

1 i+ z, M6 H" N, @9 K5 |

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

1 o* L! v8 s% }2 p3 D' N8 h( m2 ~
' f, f2 ~, f& T! J7 R# h: N6 m& L

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC6 r/ L( ?! _/ I( H1 K  D& s
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.50
0 w' @. z* [# U  _/ U4 K! k' B7 T, D4 t( M* n2 R8 T
safari 5.1 – Windows
+ R' v2 L( _8 R# Y# q" ?  [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
6 F) @0 h$ ~* ]6 ~+ l2 {9 P- K9 }3 d6 ], P4 W% |+ L) h: z+ n
IE 9.0
) x& p" q# G6 t4 d% DUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
7 ^4 D3 ^9 z, Z( r
) H' E3 O! O" F+ U* G2 wIE 8.0
; `% b; w1 }) g% tUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)" z3 i8 b( ~4 O1 q

! H, q" h8 h- N  S- ~5 cIE 7.0
  _1 I2 Y( _/ fUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
' i1 ]/ Z  n& }5 }$ g
7 s8 J. a. ~& X, o- ~IE 6.0
2 b. h' d8 r7 m: P) K9 X9 U+ oUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
9 O5 Q! I2 I+ p3 N: B# ^; q& e
1 [& a$ D2 p6 B6 B/ ^+ aFirefox 4.0.1 – MAC: J4 n- C) U1 E: X0 t) ?/ A
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
# J& Y2 ]0 T: ]( V( |: ?6 [" f) f/ f) G- b' d
Firefox 4.0.1 – Windows
% S* P+ t7 G; h8 f4 ?$ N2 Y0 d; CUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1. d& V0 [- X9 p  F1 \
5 ]3 B# M1 k9 k$ ~% o
Opera 11.11 – MAC% x3 S( E6 u, v2 M1 ~& r
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
& `9 d9 {5 ^3 f6 R8 ~# c# r  P# ~! ^2 v9 @( W
Opera 11.11 – Windows
4 u& D+ _+ ~$ a- ^User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.114 q6 E& w5 T4 c& ]/ h* O

) V. N! B: B$ P( _0 ^" B$ GChrome 17.0 – MAC7 P& B% H# k9 f+ u* g3 o" t. R
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、国产浏览器

Maxthon4 e4 h, N0 Y3 y( r2 z0 u8 z
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
* F4 v/ T" o- G! o3 o, d5 _" B( l
$ c# L- B& B: F6 {9 l: d1 xTT, M8 ?9 w# M7 D2 Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)  _2 {- Y6 p6 s# H) N

2 b0 k9 V- F3 ?+ g, |7 _, bThe World 2.x0 |( |# f4 A5 w+ L2 h. {: y
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)& I. y- W0 [+ g, M
7 Y1 K$ G) j+ D) o* Z' [6 }/ F
The World 3.x
8 l& U" j- V0 E* CUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World): Y4 v) C: c; U# D# u6 J' c( [, s

1 F$ Y' r2 m& L6 u$ G0 I搜狗浏览器 1.x2 k; m3 B6 i9 r8 a6 c
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)9 a1 S8 W5 w- x) [9 T

% o4 m! f! G; T360SE+ T, p+ x. z6 l$ ?  z
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)& j2 e7 w0 E! x) I" x

$ Z4 v% |2 B' U" ?* s! IAvant
: ~! R0 |! }4 f' yUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
. ^$ C. c2 I6 N% B. ^' E9 u( G" }1 b* j7 B$ L
Green Browser/ t% f% j) T( W2 l# C- ~
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
. U3 W& O7 E) [) S4 O$ w2 rUser-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; O- R: O, h$ X. l  v

& j" V# i7 a3 U  Rsafari iOS 4.33 – iPod Touch6 p+ R" f1 m3 P1 V( t$ u( [
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
: v5 N1 G# I: ~8 l
2 n5 \, F7 n' t9 V8 M; q% ?safari iOS 4.33 – iPad
- g' M/ x& f5 ^9 fUser-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
( B4 V8 j2 U; o4 T4 L/ K4 _# c2 U% R( y2 ]6 y/ Y
Android N1# Y1 R" U8 N% q9 \. ]+ y9 \
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+ X0 N7 R% N. A4 }; K5 R- s

' g0 u0 ]4 ?& Z0 bAndroid QQ For android  k5 _0 j/ J/ {  f  G$ Y5 d. ^/ s
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.10 J8 L  C3 }% f3 h$ R
! B3 m1 w$ N/ q8 w
Android Opera Mobile7 X$ |4 |) s2 q: n2 j. o
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.109 Z; [* }0 z2 ~) E- e
4 E2 S8 b* e6 Y4 y2 X
Android Pad Moto Xoom
* X" R5 E8 j. a$ K& DUser-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
; r8 J( b- s2 I( R' b/ N" o9 m) E6 \
BlackBerry9 r% d1 @- z  @% Q
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+
- T; D0 ~. {" {, D
6 p& f$ X; u& ?% L; d' \WebOS HP Touchpad/ s) W1 H5 Q3 X7 S
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; @- l( K: {- Z% b/ y
: O* |: ~) R* _& m) }! {
Nokia N97
$ s$ v4 X0 n3 v$ _7 hUser-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
2 [6 F- L3 d' l8 \8 B( ]9 M$ v& f  Z3 j  ^$ c
Windows Phone Mango7 |! l; e, w* y2 D& w5 v
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
) `. t- a/ g+ R5 }6 b, [
( i$ ]0 d. _5 g3 e2 J0 oUC标准
) e- \& Y' w4 J& VUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
+ K% ~( }* B+ v" M' a/ N; x+ ^
UCOpenwave
) S' `# \: R+ N0 _( sUser-Agent: Openwave/ UCWEB7.0.2.37/28/999. Z1 m4 X* Y2 C& I# o' t
8 P2 G- e+ y2 ^. f% b
UC Opera7 b8 T% H: D% C9 b+ ]
User-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
互联网安全