Board logo

标题: [其它] 分享php/asp/asp.net aspx判断百度PC端和移动端蜘蛛的源代码 [打印本页]

作者: jfx    时间: 2016-8-30 17:38     标题: 分享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.         ?>
复制代码

! v' u3 _2 S3 G. p9 T- @


; J1 O& E. n8 V  g5 L) y

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.         %>
复制代码
" V2 _; n; S9 k2 e: a( B

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.         }
复制代码
* ]2 F! ~5 J1 q3 U& r

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


! n) @1 L% V& [9 I( `6 b3 j: A' C, I% f6 S" V

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC$ O6 V$ F/ Y$ a. K( [" y  u1 }  ~! o
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" ~3 [: B( U8 T0 \

/ O2 Q4 r, j; p3 Ssafari 5.1 – Windows; ]; t+ g( ^/ Z. R% m
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" a9 ~5 M/ c2 _2 W6 \7 ~/ }
2 {& \# O0 N/ Q4 T2 d/ N% u) ^1 UIE 9.0
. R& H2 _4 h( n& `( r4 DUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
' u- C9 W7 \/ ~, _7 S
( N6 l+ B8 Z, [0 S0 M+ f. AIE 8.00 J8 @1 Q# |) |# x# U
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
: A% t8 r/ {  t2 w$ n1 t. K% ?" H. H. M( a: d
IE 7.0+ w# d+ w- |* D+ t! R
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
, V9 D+ F: x: L  _6 J
9 M4 [2 P2 ^) M. EIE 6.0
# r4 u* i6 p9 |. G6 P7 J- ?/ J8 GUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
# P2 |4 b7 a. o  e# ~8 s9 T& q/ \3 e* ^
Firefox 4.0.1 – MAC+ d* ~# g) L% G( Y' Q
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.17 y; G0 }; ^  s' i
$ S* }# y0 ~, t& v
Firefox 4.0.1 – Windows' B; K8 M! S4 y
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
! T$ _+ y% B0 t( Q1 Y
7 B% I/ T+ o) X# T) w2 U& T9 F; _Opera 11.11 – MAC
* P) H4 Y4 ]/ v, o! M$ sUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
6 z0 M' g/ m9 m' E# K6 z  ^, v: d% w/ L, Y6 a  f8 i. T  G
Opera 11.11 – Windows( t7 b% G/ s; I/ H
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
, I+ @6 u1 _- I1 H% T- C
$ o6 [( r# C) w$ g, R" }& ?' C, eChrome 17.0 – MAC9 b$ K  A- L! z/ E3 N  \; i2 R
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
+ H1 M& d$ X+ x3 WUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
8 A9 `+ K7 b* j, `' F6 E6 C# ~. Z: O. {) {; F9 d
TT
6 S! R: l. L4 P3 e6 m. VUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)( p# `! i  ], D3 m0 B
( w4 s) c+ b; N. B' _5 F. C1 {, }+ b
The World 2.x! F; |3 R/ \/ u  u, t4 }
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
( r& V: D: `# E8 N8 i: b( }1 T' P6 f: Y
The World 3.x
! D, h) \/ h. }1 D' [0 _( ]User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
3 j2 p6 C2 k5 Z3 c5 l5 ?7 g
& s; [( b, g+ b* K) ?搜狗浏览器 1.x+ ^/ v3 p" j  y$ q0 I
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)  B$ E! C( J2 T; s5 ?! C

/ z, A8 p& p* ~5 b) f* G/ ^- H360SE, ]& @& M& v2 V; m% ?/ Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
) B# ?7 S% l# k2 \  Q) L0 U/ p, p$ S% h  ^% Y1 k8 a0 W9 _2 Z
Avant
2 V& ^' A/ y: i. n" n3 j) R4 m8 iUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
1 S6 Z( T% F/ S+ z# o2 u* R/ m
" {7 e2 V$ `7 D' o# rGreen Browser
$ M1 |1 Q! R5 O9 T4 a+ rUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
9 o# W0 ]' R4 J; A* y6 c) `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 t& m' ]8 t* N8 R  y3 K- X, R' A! u& }& C* O
safari iOS 4.33 – iPod Touch$ V& w& w, s6 ?8 a9 o) ^
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
) j% X9 P9 ~5 Y
5 |5 G- w: s9 ^% Z* fsafari iOS 4.33 – iPad
8 n# F! Z; F6 C( jUser-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$ y; `1 n3 j. i  e0 `6 \) W. Y
) ]% U, h, I3 T
Android N1
8 N# n$ t" ?& 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
: v3 k- G3 R4 z( D% J! q; e4 W% w" C" F8 Q# `
Android QQ For android7 ~5 n2 ~6 J0 K5 u# F* n
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
& \7 K; b/ C5 O0 k1 t% S
% ]: d$ f$ w7 r  _$ G1 i: m. @Android Opera Mobile) v- K. P& l" Z' N, H6 ^& @
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
' g; j) F# b: z2 l0 Y* M5 h: E7 ~( T& t- K4 F4 z! a  a
Android Pad Moto Xoom
" e' C; a. Z- ^) E8 fUser-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- h) c4 P2 i& N3 N1 f8 ~8 j( p0 V

; r9 ~& g% m' m- }3 `' R9 x% oBlackBerry1 M# J$ z  K9 }
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+
' q/ R* Y/ N6 W+ a6 u1 b" m( t% I# k& g9 d
WebOS HP Touchpad4 h9 b8 k5 `, c5 R3 K
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.0
8 @; T) U' ?8 B7 n; x/ g4 F. e8 v3 L8 _5 s
Nokia N97
! p3 H3 `- r3 u) ZUser-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
, W7 W) {+ w7 k7 _5 y% r9 T9 ~
% @6 {, L4 @& G( N- }9 ?Windows Phone Mango
  P; w8 g! o: U* I+ h# g, O0 [( B9 t* hUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)- b! M5 Z" G: v3 d7 H. }

/ j- E% N& P' q7 ]UC标准8 B  G- B/ i( }# ?  _% Q
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
$ I& g. W: A( `1 M6 j  K
$ l2 T9 a: Z6 D3 ^0 j$ I$ VUCOpenwave% c6 u* [: H7 D4 ^4 [, J
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
4 [* h  r1 q) W- l# y- B3 x! |& ]' L/ d& K0 u! N
UC Opera
7 B. \$ h! i$ B) r2 }+ sUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

参考: http://www.webkaka.com/tutorial/zhanzhang/2015/060421/






欢迎光临 捷飞网络论坛 (http://bbs.fjbjdd.com/) Powered by Discuz! 7.2