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

6 g# T  u6 ~; c4 F, B- P! B, `


/ x( f% G1 `+ e$ C' M

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.         %>
复制代码
9 Q$ y( s3 g5 k$ m

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.         }
复制代码
3 g3 F# r) L% y9 W; n  g3 U

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

2 }4 v0 J& S. [3 e3 k
7 Y7 `, @* q# _2 J  j& s) \

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC7 V' Y( E& L6 A7 t
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
, H( S1 j4 o# Q) j6 e* [
+ _7 A2 M) m! Wsafari 5.1 – Windows
  ~" V; r9 z% Y! |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
( i3 j( J# B# ~4 A6 ^1 ^; f- t9 _
3 ~' Y2 d$ Y: w" t1 NIE 9.0: G* }2 M8 ^5 A0 r) n5 p7 q
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
  b; c  ?4 [/ |5 @1 t6 _9 e. p7 N" C/ c+ F" `% R
IE 8.0' s! I' c+ u5 h& q# s4 B: @
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)0 Q1 R6 R1 j! j- f5 v
  d, ^& I$ _" B
IE 7.0  z+ C, q+ j- v: _% c, ^! ^" O. G0 I$ X
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
2 x) }2 @% c, v) q9 L5 k% H& r# a7 N7 l1 [4 H/ \+ @; k  m7 w' I+ `* e
IE 6.0% ^) k+ I7 E: A0 p, \! \( C- m' p
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
( D: n7 y: l" j/ Y* @( u  _  {- ^5 F/ J
Firefox 4.0.1 – MAC8 ~! W) p/ t- y, W" s
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
' w' [1 Y9 [8 \6 \# D1 j# x: w0 ]9 S1 a" e( N. r7 r
Firefox 4.0.1 – Windows5 _1 S  |" M" U- \3 B9 R3 O
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
) K; k9 K$ ?; D0 C8 X3 {( p7 Z' y. \. l0 W$ a& @" @1 q
Opera 11.11 – MAC/ g+ `/ a% u  ]& K: J
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11; v6 N4 O# i! F) [. U' V- q" x
3 X' a) U/ T* i# {/ C
Opera 11.11 – Windows
* N6 {3 s+ p& F, h6 u' rUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11. A9 p* j- `. I
, x9 ?) @7 N; z
Chrome 17.0 – MAC  b  K6 @2 ~6 e2 n0 F3 n
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# N- f( L2 o" [$ m
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)7 q, m+ D( ~4 u2 J8 y5 e' n

  b8 S! x0 Q, w! _' P+ iTT
* \8 u" u4 q* Q: D5 ^/ N4 D# nUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)) b  E2 {' o: M
% j9 ^3 D4 o3 ]' v% X8 s
The World 2.x
) K! P+ w2 Q. X! V, ?8 Q5 {0 O; g# UUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)5 q* H& v' d1 X8 s8 D( \0 I8 M

0 D: Z# N) i$ o8 N* AThe World 3.x
4 m: ^& t8 W1 i* fUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)) U/ ?; k5 _0 I3 i$ O

( e7 E8 j* X, |2 Y搜狗浏览器 1.x( d" G/ X% D' l9 g6 X5 ?
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)
: ~' r: k% F0 X- ?" j; i
+ O6 @4 h: b7 h% y360SE
& w9 K7 N$ t% Q0 O% A5 zUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
& f! r% u! ^* V$ K0 j! d. T8 F9 {! [+ \* {# T
Avant
+ a8 {. G/ Z3 D8 Z8 \5 T) PUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
* s. n0 ~1 Z( Z1 @1 [& L# _, G% }! y- \( |. s
Green Browser
- V# l0 w$ F6 k. i' m5 k% w# |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone0 _2 W* e8 N3 F! f0 f, f: f& e0 ]/ K- J
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, E4 j6 d1 N- K
! D& J9 @# z3 r) O- b( f1 Jsafari iOS 4.33 – iPod Touch
, g1 `# U2 k; E$ D/ AUser-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.54 w# G- R3 i2 ~* R, N3 F, V/ ~6 V
9 t+ [: P8 o: ]4 k3 [
safari iOS 4.33 – iPad2 R0 i5 c) F! e
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$ j2 Z% a: p! g- Y5 q
8 I! W4 N3 ^, f: H" o
Android N1
5 P& Y- t9 X7 ~/ Y! Z3 |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.11 h5 T! k/ o- u, X
! g* Q! Z1 Q8 _/ e: z- v( v
Android QQ For android* U. E' I% T9 Q4 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' b9 t* d+ q) ~

( q9 U, K5 X* U) g2 s7 P$ D; k$ QAndroid Opera Mobile0 M2 I' C9 _* ^% n& \* V* s- k
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
4 G/ |- ^# F% B/ a- E
9 `  M% Z  Z2 q# y# n+ i, XAndroid Pad Moto Xoom3 {7 M3 D. c! [$ I3 p' t! J3 d! y
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
3 V' s3 a; a/ g  O$ v0 A" i* j3 `' ^" C6 s+ b
BlackBerry! G/ R7 L- P% ?: g& x6 d5 M
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 ^, v! l2 w% [: y% b# d' d2 a

6 G. k* I0 Q, @( SWebOS HP Touchpad
2 A" Z3 C2 L& k9 QUser-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
5 _0 R& d. P( ~9 n! |  U6 Y# B
+ Y8 E' p+ _7 D2 L% B7 CNokia N97
7 A. M  [' {1 k. c  A" ]4 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.181244 t* h, @+ O7 L- h

7 I5 y& ~- @+ s4 H6 }, C2 [Windows Phone Mango& n9 L* ^$ c$ i8 c0 j
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)% a- o  D9 K  N. q1 h! F0 f  C: ~! d4 K

1 }9 c3 M8 G* a% u( d6 s, L4 k+ k: ^UC标准
. I) t% r4 r& q& x1 V5 K+ Y2 e/ f7 uUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
7 D- P2 A  b5 Y8 D2 ^9 V+ O* k% m) L' n  c! x: }
UCOpenwave
  ]% N4 r8 x3 b; t' v) ~User-Agent: Openwave/ UCWEB7.0.2.37/28/999' Q& Y3 w' g! o/ H* c/ m

; F5 c+ M* r% |- @) M  X% HUC Opera
+ t! J" O. P4 e, W8 {3 aUser-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
互联网安全