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

, @/ I% a1 {4 b! X; U

- R4 B: C8 a0 f6 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.         %>
复制代码

! g1 |: W7 s, p  P6 F8 c

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.         }
复制代码
4 W# _8 O: j, u  ~

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


8 e; \" G3 \, z1 @6 U1 v0 n* Z
+ a6 @+ y1 f" d6 M9 [0 L

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC; v! h6 ?3 C* G2 I
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/ O! K, L" F8 k6 H2 V: q5 @" g
$ g% s6 b5 N4 F
safari 5.1 – Windows5 j( D1 [4 l4 |1 p
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- e4 e, Q% \9 e7 c9 y- V& N0 R
7 O* `" w4 w4 j# O+ B5 L" a
IE 9.0+ B+ w. ~- z  r1 Y* c
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
. |9 t4 t  s+ T
5 L  M8 b/ b# R7 h( SIE 8.0) I  ^* o) i- _. a
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)8 e5 F5 m/ R' ~+ B1 ]
& g/ v' I3 l  `3 ~/ r
IE 7.0+ `% l7 q* D0 U3 p: Y
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)3 \2 m  S3 o0 r5 d' h& @7 \9 ]

' N$ z$ N. S# \! g4 s; L% MIE 6.0! Z. e5 e" g$ i4 n% N( T
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)% ]4 g2 j. U+ _4 X/ B
' W& ^3 q: x4 }5 r5 W0 a7 E! @4 X
Firefox 4.0.1 – MAC
  J* X8 Y2 l3 LUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
5 n! E7 M0 U& |5 r1 X' N3 P0 l+ V
; M# Z" p6 V! s) @Firefox 4.0.1 – Windows
, f+ a1 [# T5 F+ B& QUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.14 Y, A9 o/ @& X+ ]* @
/ Y6 u8 n' ^; y( c
Opera 11.11 – MAC& x4 e$ K& @: p' ~
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11- _0 I) P; B; w, |% A  C: S

$ Y5 X1 B& R) m4 S% iOpera 11.11 – Windows) D7 p& ^- |2 Q: Q% o1 K6 s
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
6 i; w2 F7 T) c2 b$ p0 f" h6 T6 W6 o: J2 C  s$ S
Chrome 17.0 – MAC% S1 t/ G* n. {( ^, p4 d
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
0 F: U" G5 Y- MUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)7 {# F& C' e. x/ Y' ?* z/ a) L6 V

" u  F. ]) v9 L* i2 R" vTT6 g! z0 A# r0 E2 d, D2 C
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
8 \% b, Z) k: o1 y2 z( Q# g- A
0 c5 M9 c3 O# qThe World 2.x. I3 J$ H3 M) m- U+ r4 X' K" @- n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)) D! m$ s) H  n8 K5 Y. T
8 W! w: a& K( f3 Z! G- `3 J# [/ G& Y
The World 3.x: }( }# H4 i6 P: X7 @4 C& y- y
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
+ A" |% R$ c2 \7 w
- x( ^. D7 {1 x9 y搜狗浏览器 1.x) g0 W/ R( J2 h+ F+ ~
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 |, i, V: C! l  E+ \! }: _" S* f/ e: }- ?, |
360SE
, k: g0 }& `. @- Q. _User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
4 v# Z0 {" r, t$ y  \- `5 n, u. s0 |& k0 [
Avant
2 r5 O1 ~0 A3 M  z4 n4 ]User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
& x; V: A! Q! w, X% }9 C( o" E0 O, C: m1 Z
Green Browser0 A! x# @! P) S- }
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
  [# I+ s% o3 e6 CUser-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
% C# ?+ C* g/ h+ \
. H) D% Y& y. @safari iOS 4.33 – iPod Touch
: H6 y5 u3 T. ]& X3 PUser-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.55 C1 L: t& c) u- L& J, Z, I# E

' W* i% D2 Y* n' d6 isafari iOS 4.33 – iPad3 Q' ?( }" G3 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' P3 G$ S% A" t+ d* R; z

3 T) F6 u( I& U$ H2 a$ w. Y/ i1 v. gAndroid N1
- I$ w  B# S$ r  H) p" LUser-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" @6 x6 {  |% x1 _) F0 l

1 J0 T' M: m; P7 p7 [  PAndroid QQ For android
4 s6 t6 u1 o0 E* ?( w+ mUser-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" l4 J5 X) g( N& |; f  L
+ h/ N4 k) @8 Y
Android Opera Mobile4 @$ N% k' L2 ^# v* M+ f
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.104 `  x9 G# z2 ?( I
1 c8 Z1 T& Y; N
Android Pad Moto Xoom" Z$ D% o- |% U. t$ A- j
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
( G; |% j- _' ~: Y7 F, g* O
1 G! h4 Z  T2 t$ c3 `BlackBerry) a' G/ \# v& o5 K! I4 I8 I6 M+ i
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+
. X5 ?$ P8 b; n' ?7 H6 K
6 H6 D. ?+ j8 D) t$ c9 Q: L7 jWebOS HP Touchpad
* l1 ~( u1 a3 n, sUser-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.07 @" V1 S0 r3 @% T5 D% \# d3 I
4 @4 d1 h5 H. U8 U9 W
Nokia N97
8 K: W# R2 o3 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.18124, L6 C- g2 s4 X4 N
  b* i5 V7 r  f& s
Windows Phone Mango; ?& d2 p% M" d: l. y3 }' z
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
. P/ G1 A+ \, {3 H  E6 |! g! T& Y6 r3 M  t2 V
UC标准
. Q) W- z1 y" m1 d2 l. z3 Z  kUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999% B* P! u1 P7 ?: p7 W! S% G
1 @" d& y% b4 B- o2 o
UCOpenwave0 B4 E0 U" Z$ ~, q8 Q. k
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
; B$ C' a) |1 @! G, n# q7 d8 h% y7 r: V& f* j+ u/ k$ W
UC Opera
" f/ V+ a; ]$ u4 oUser-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
互联网安全