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

& m9 M* Z3 _. {( `3 U4 O

: R$ Q/ y7 [4 a: _6 B1 V& E

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 K7 C* B: L4 w( _( y2 M/ t

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.         }
复制代码
" `" H. K( C' `

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

) A# Q/ i0 |5 r; a. Z; j% k$ H

: ^  j" @! B3 L2 [3 A

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC0 @2 `  v6 I" X( j. E
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.506 X( t) A4 [: L+ |8 {8 ]0 c/ J/ t! J

' k3 e+ ]9 ~. d: q! J: vsafari 5.1 – Windows6 R. v, m) G% H* h
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: f8 [$ B! q1 ?1 ]1 \

+ m$ L/ K+ p( u) k; b2 iIE 9.0  u9 @/ @! Z7 Q5 K' W. ^
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
  L8 {6 |4 ?( w4 D* F
9 V2 M: q% A+ ^$ OIE 8.0
" Y! ^9 q; V( NUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
5 d' |2 ]1 m+ B1 b- o
4 K  ?. O8 y( |3 i8 n+ kIE 7.0
( G" W! h5 ^% \! @User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0). |/ [9 x4 P/ T4 @$ H* Q1 [
" u) _2 \) u, W; P, n
IE 6.0
- ]+ j6 x9 S( m4 k9 |, X* ]User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)) O6 r5 K# D# V7 x$ L

" N# l' e* x; s/ `4 WFirefox 4.0.1 – MAC
3 W1 d. F  K' U/ _) R) n- L% KUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
: ?1 N, Q$ j+ N/ t# U
* V" g9 Y$ n; Q2 ]9 T& Y4 j; J6 KFirefox 4.0.1 – Windows1 v( A  _- H. U7 W/ i  S
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
. L# n2 c- e8 J) W0 J7 g2 X% P2 Z8 x5 N' l2 k4 K6 t  S- ?
Opera 11.11 – MAC
" a/ f3 X& ^/ b: X5 p5 jUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
& R* b" g1 e: R/ [5 b) Y* d, ~, e5 ~  @4 k7 M" |4 D
Opera 11.11 – Windows/ x0 n3 [; u# I, F8 g
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
0 Q2 N2 M' ?  e0 w* X% q1 B
" x  d+ |6 u+ z& q; j7 NChrome 17.0 – MAC
' q, u" b8 j6 C# iUser-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 {& K. M: A+ z$ `( _3 X4 H4 v1 p
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0): b. ~: M6 O4 D) F5 U. v0 P  a

# X3 T  g6 R2 X9 R; WTT9 _# `: _7 W& d$ M7 V9 g
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)* n$ T& G! ^7 f1 V0 g
& D/ A+ i4 |5 i5 O& [
The World 2.x
3 J0 l1 ]' z3 j$ k  JUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
2 i9 \( O! U9 H; p0 K9 b( r; i; H
The World 3.x
$ f" V' A9 v- r. q' U9 X% f. O( VUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)# K2 m4 {4 a6 [5 l6 z

0 d& Y  I2 ~5 U* N4 G  [) x0 ]搜狗浏览器 1.x  W# \& U: x3 ]( C  w- L% h9 O  m5 m
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)
2 G7 p( p2 G* k6 y: X1 Y" Y; g7 V0 S7 x6 `( J$ w6 }  Q! w# ^
360SE
7 |9 U6 K4 o, m) {3 w# H: YUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
# g( P5 L; R: G% s
. ~8 w* z$ M- u6 [! n# b4 E' ?Avant
7 h& Z4 L" T2 [; m8 c; x1 C# v' `User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)- M7 K* l3 x7 Y8 ], L, s
$ h! Z# C: ]) V  u; e* q
Green Browser
, `- p9 z, [  }6 }# \User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone; B0 B7 u9 ~/ b- j; u1 D* A/ Y7 W
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
* R' V' j  n" S$ k
# F3 F6 k+ p% h4 `5 i1 Osafari iOS 4.33 – iPod Touch. Z0 F5 K' y9 Q/ f1 \+ 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.54 }) n6 p; l1 `- j

( W8 a: E+ y) J( P! |$ Vsafari iOS 4.33 – iPad
# D" `+ C3 L9 v/ 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
4 Y4 @. V8 Z& C  O
) c+ z  {4 U+ SAndroid N1# }$ i0 }% B  ?
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.10 T% S+ I+ k, h$ v  z3 j
. O9 k9 ~0 j$ N; k* `" _! ]$ S
Android QQ For android
# B. x7 g4 f% M) v: x8 |/ wUser-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
( h4 V' H7 ?# z- W6 S& D3 D) g% C' Q( R$ S# N
Android Opera Mobile
8 m" H: Q# A! `( I0 f6 jUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
# g; {+ u8 `, |7 H; [+ Y1 D3 q; ?( Q) W( \! n- V( {8 P
Android Pad Moto Xoom
! _' Y$ i2 [! i; BUser-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. n) L2 \8 p7 s( K' o1 {. C3 b
* Q# k$ Y9 o: t6 y2 h) D
BlackBerry1 R0 x* G6 T! G2 L
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 d/ n( f
* c, t& I4 Z0 S8 b
WebOS HP Touchpad
6 b% a4 g% o) r4 e/ t- jUser-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 {2 ?: W" @5 c9 y" V

6 J  B* H; `# v6 l. fNokia N97! f; [  i7 M, [
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.181240 z1 e7 d) R7 `
* k  G# z6 C; v; [3 r
Windows Phone Mango
; d" c5 Q* G# r, @User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
6 R, o+ r4 V8 c8 V. E* m* o* P$ g; K- S7 I. V& C' n
UC标准
+ J; v  h  s7 S6 h) `; H0 H6 rUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999, b. G  `2 N8 K) l6 V4 j

0 R  Y8 D  A% H( h1 pUCOpenwave& D% i  ?2 j" w) k2 U0 _
User-Agent: Openwave/ UCWEB7.0.2.37/28/9990 Y' Q& _7 s3 D0 Y
; y! B4 O9 r$ y  s- a) N8 P
UC Opera
4 {/ f) h( y0 e3 q) QUser-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
互联网安全