$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.         ?>
复制代码
' w" Z1 ^. ^$ V& V7 Z$ ^8 e

  S; Y0 T# D* t( e* q

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

4 H' s  N9 P% f: e- R0 F! J

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

( S! G. E& `8 w

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

: l; g1 j' m% C  j
- ^( ~2 i+ o4 p9 K- W2 v

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
- C6 @* i5 M$ k0 b+ t+ s+ NUser-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/ G5 z- l4 t7 s! A, M3 q) H

2 h* N- b% K0 R+ L& p, v2 {% Vsafari 5.1 – Windows
  `1 w$ e( X! M5 A- l7 j" ]User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.501 R' K/ w2 \- r

3 @- P( B7 V, r$ vIE 9.0
& s- e: X) m' T" LUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
( v. D6 e* |) c. L6 E) {+ I( W  C# Y! I+ s# U% ~. m8 x) T7 _; ]- z: T
IE 8.0
$ s" `+ ?" `' J0 L! |" A0 }User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)  f. C$ }* W: O; F* [
/ M3 _5 t  D; A9 b- m
IE 7.08 `' u+ `0 o5 ]3 Q8 r# X
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0); K1 H: O8 I0 d" ?

5 l1 u8 r% K8 P$ l4 g1 P+ iIE 6.0
; ~+ T" v  F; I! a% G. N; fUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
% R) H( b$ _8 ?
' K. v/ @, L- Y& T. J0 O! E3 \6 XFirefox 4.0.1 – MAC6 m7 y" y# U3 W# V
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.11 _( Z0 a5 ~. A1 g4 i
5 n4 u$ i6 J- O
Firefox 4.0.1 – Windows
. G6 A7 s" V5 L6 \) vUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
* X& `  v3 p% A0 j7 t- n$ x. X) ~$ O  G4 H, u
Opera 11.11 – MAC  `5 _( H8 N. d; u# I4 T
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
" ~% J3 K. x6 _7 X6 l9 i( Z
& {7 T2 ]+ C9 \, j; j  iOpera 11.11 – Windows
+ ~9 t) Z, S2 D& D. A7 oUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
: e# J- {9 i+ I
7 I6 w" d0 I; C! d& GChrome 17.0 – MAC- H, Y' f6 z9 }6 G) O
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
+ I4 }+ B( u% J6 ?2 @- kUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
9 f) M* o0 g( {. k9 Z: I! k
2 t6 r6 X: Z6 b8 E/ }. yTT
6 y+ p! `/ }3 V3 v) N6 ?& T# aUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
+ X6 Q$ x, z9 j8 \% o* x; s- K! \" n; N
The World 2.x
6 \# [, d$ q# ~3 x, B' H; G# ~User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)% u5 ]% m4 x" t( n

+ O, p& C! C# z, y4 g3 Z, s! J, ^& N$ tThe World 3.x
+ t$ M  i+ z- K$ Q/ e* vUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)% J; _9 L/ X" R$ u4 Y

3 ?8 c& J- h. w0 _* o8 ?# g搜狗浏览器 1.x
, i0 O8 [, N1 iUser-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)
. X1 S4 ^! P+ ^9 W! l
$ Z4 \3 j% h' i7 W360SE- f* i) E7 r8 r5 B) F3 A
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)0 _" U# }# v) Q! p) w6 b

% ^% j! P- Q) DAvant
; z! m) t9 L# ^+ y5 I* \- Y$ tUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
* D, u6 F" k7 l; w/ J0 `
' q9 h& c% A* O5 [Green Browser
. d8 M( p0 t4 o5 f9 E  fUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
1 ^) i" w) Y! s$ i5 _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
5 L- x( i  C, g  N& D/ n1 ^3 f
9 z: p. Q7 O: G+ t! Z! U. Esafari iOS 4.33 – iPod Touch5 U/ m1 a8 k/ ]( I1 k$ `
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' b1 S2 T$ x* d3 ]
7 _- B( Y! Y" |# H" Vsafari iOS 4.33 – iPad
1 t# G7 g) E3 \" wUser-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.57 w* ~$ x$ l; F! R, E5 n5 i* C6 ~

0 y* D, e( D: e( @& E  s4 TAndroid N1. O7 ?" e+ K) T9 m3 ^3 n4 m
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
9 S4 g# g1 a$ p% x0 }
0 |0 b7 ^2 c1 W/ s2 rAndroid QQ For android
+ R6 g$ p5 l1 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
4 E* k1 f& l, s% Y2 y5 S$ O5 E3 b3 b  a; p. _& @) H) I$ R+ U1 I- k
Android Opera Mobile
! l( @: a1 D1 H) D- ]! g- K4 h) pUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10. y/ p8 j: R  h

! G6 h- d, |# l0 eAndroid Pad Moto Xoom
8 v+ I# e% L* j. d7 X- a0 \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
) A5 [! Q" u3 n7 ^: c
  c# V: b6 N: rBlackBerry
9 e4 Z2 t- N6 A5 [$ RUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
" I4 b9 O- N6 M- b# {' w8 h: N
/ e5 K, O  p/ E  a8 X; R. qWebOS HP Touchpad
( ?4 [) e! O- l8 v/ iUser-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( ]8 ~' L! A3 @5 ^* ?( `0 ^+ K/ r

- V6 U; c/ E4 M0 Y* m* P5 R. PNokia N97  q( h  e) Y2 M$ w8 @
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
, B9 e$ r! b# U4 i1 E$ c1 u: T$ ?6 U
Windows Phone Mango
/ p/ n; p$ r7 B! M7 v! G) |7 DUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
  L6 Y; _# P2 H( W: ~
+ e6 P& w, G  O3 w; _UC标准, F/ O( U5 C9 t9 E9 G
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
8 @+ X; a/ T! ~; J3 ]( n
. o. V4 d8 T+ T0 l# k/ Z6 HUCOpenwave
* j3 M$ Z2 _7 ^# ^6 @* q4 m" }User-Agent: Openwave/ UCWEB7.0.2.37/28/9997 Z  P9 o& A8 Q0 S+ i5 B
" J# \$ _. K0 H6 ?( b2 B/ U+ A
UC Opera
+ }6 l3 |9 ~" E" S: x- `* vUser-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
互联网安全