$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.         ?>
复制代码
# R% A  l% G; _/ T3 A

, V& \1 z- B7 O) N5 K

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 T0 Q, e# @" q6 w

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 @* [$ ^- N" e! z

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

5 ^2 |) x+ _) y* O2 G. c, H
! Q  B! \1 ^6 x

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC- g* A4 w, `" q3 Y& C1 o# q( y
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
/ ]5 `5 l* V; G3 p# v6 T( v, I) \5 C0 Z$ c$ C# f( p' W5 c$ h. O
safari 5.1 – Windows. T6 Q# M& F9 ]/ W/ \
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
+ \# b! X4 W" h4 O/ g0 x
" F: x8 y6 m' F' A& m# SIE 9.0
+ s7 U) c  G9 a  b/ J$ J7 X/ ?User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;. h8 `" `+ H1 K3 F% Q
1 A/ a& B1 k+ B
IE 8.04 x1 H) q2 h9 Y; J# g. H
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
) i$ I; o' A+ A+ b- d$ Z9 Q3 ^' _& M: W; \4 K' L, F+ }1 j: l
IE 7.0/ B) Q9 a, @6 ]% P$ d+ ^3 e) o( O
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)! d" y8 ?3 p" Q
; o6 C5 Q5 v& \- ]" r8 }* J
IE 6.03 d" k: X! ?  i; g3 [
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)7 u; ^# a3 i, w$ e3 Q% i% A+ W

& _/ G9 `# G% J! z1 R# P# NFirefox 4.0.1 – MAC
3 q/ Y0 Q& \+ ]7 ZUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
& c+ U  e+ X9 ~$ U* \7 G/ `' f4 i2 e0 }3 m8 C3 w
Firefox 4.0.1 – Windows4 z; ^+ n2 P) ~4 N
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.11 }5 h4 O4 X8 V) ]0 S$ }
! _* c+ I8 R! a, |3 q1 Y
Opera 11.11 – MAC
! h) M% i  ^# Q2 [& vUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
5 f/ k  R& U" H  x% P1 }' n6 L$ }, T# i: ^3 X' @4 J) [
Opera 11.11 – Windows
, Y! ?1 U9 P/ H; A) z; Y% Y+ i/ ?9 tUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11% D$ k. `, P& r8 L7 S3 H! S
  }5 D7 p* s( C- V. _
Chrome 17.0 – MAC) V4 j7 n" J6 [" S! }
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: w' U' S5 j( @
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
2 H1 T" s$ j+ V( y# v+ H' q" O  h+ E4 C. d3 F4 i  d9 g
TT
" l/ c. Q" ^) L# g7 o0 ~User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
# j+ ?; g9 B* m" w$ e/ S, M! ]1 L; T) d
The World 2.x
. R+ O  |  B* F5 }User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)9 a, J7 @# u  v
& p- B+ U3 f4 y, L" Y
The World 3.x! U: g4 c2 ^( X' ~: n/ G8 ?
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
" z6 b2 `1 K) V' x1 B# r2 q. P: _) K# r1 h/ s8 E$ j" e& M% V
搜狗浏览器 1.x
/ J+ }1 a, @6 j: Z5 SUser-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)
8 V3 ?" E! q! Y0 |) T2 [( V, o2 D0 J2 G7 V
360SE
! t$ K7 W9 ]6 YUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)8 F& ^+ Y1 `* o( C& q1 z3 T
) a: c' X/ Z; z. f$ s9 T% M. Z
Avant
6 [) ?4 z" S4 o$ W5 M+ |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
; f0 w& {1 Q, a. J1 ]. m$ B; @5 u6 s/ N4 w# N/ N2 p
Green Browser
% Q) ~( g/ J, nUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone* v# _: x6 U: {, ]0 m
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" q; g$ {& I$ ]8 `* J8 u) N

* J4 _) A3 l' U5 N) ]safari iOS 4.33 – iPod Touch
& t6 y. i9 L8 }# IUser-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
. O( S$ |  }! ]8 I5 x2 `9 W
( H; J8 x# V: K/ q1 X. p4 osafari iOS 4.33 – iPad
- K$ Z" e6 _; x+ Z0 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
! y6 L% F6 a7 E3 X+ A5 e: ^
. ?+ v$ j% o+ t! B7 A. zAndroid N1
8 R# \4 G: B3 F  n  o" `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' v5 r* j8 K0 ]# w, e5 i1 V; |

4 U7 f# g: S/ UAndroid QQ For android. p7 a, H3 s" X" c( D
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
; X/ D. b/ y  x! I7 Q* N& R: p2 |# h# f( }0 H! y8 y) G
Android Opera Mobile. {5 V$ q, b2 @" v! T- x- W
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
/ M* e  \5 Y4 y; J8 U# K+ a' E, M/ a) {3 M1 @4 T9 Z
Android Pad Moto Xoom
9 |' s" s  R3 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' r' B, A# p- R2 u

6 R) m3 l8 D4 o* l& E5 t# M2 e$ RBlackBerry
$ K- w' F7 X( m3 z8 T6 d: BUser-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, b# b" w& F( ^$ b8 d! d
: x' a( s/ r4 [4 J* W( I! ^WebOS HP Touchpad7 k2 W4 f! m+ C2 r  a1 @$ R" W
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.06 z( v+ I7 D- r& [

+ e' i7 M& Y, l9 ~Nokia N97
  ]8 o  A+ c9 S  {' \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% @3 s0 ^$ F" ]0 H0 X9 J1 I
3 J: Z' {! }+ _- y. I
Windows Phone Mango4 y* u$ K2 S* D3 t. f+ q4 X
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
0 ]! G7 t) B0 W. D! k! F# L% f/ t7 ^. o" X- N3 `0 X
UC标准
1 Z3 I- i  p/ `) gUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
  j) u& T, Q9 b5 X& ]1 O* x0 K( S0 f6 t" S; C, M# k: d0 ~) R
UCOpenwave! J2 u. v7 s$ A) S3 e: b
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
, Y1 n- j5 K( T6 c. J6 ?' e! @6 X
  b* Y: B/ U; }1 {UC Opera. k' [- e& U" v, ]; B9 U9 F
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
互联网安全