$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, v8 m' d5 z

% Y: B( G/ K, O; u3 {

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

1 w0 D* o" q# }$ }! R% Y! f3 v5 l+ X

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.         }
复制代码
) T1 [2 A  `1 {1 D6 f% ]3 q

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


4 z3 J+ \% p7 o4 Z, r# l9 @0 [, Z3 s5 i5 U: I: m  b; _- c

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
$ |$ Z, e0 B1 m9 b% FUser-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
" m# Y6 I3 s0 ]2 e
: Y$ H% E  U  Y6 Q8 \" }- I+ A  I( rsafari 5.1 – Windows7 T4 W- _4 W9 K' i% a# B$ 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+ ]" ]1 H7 J. e6 L9 D8 M: Q2 S$ N
7 W5 w( [! g/ K/ `3 N
IE 9.08 [4 ^+ Y. ^: x
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
) H7 ~. f8 h+ V
. F$ E( P2 Z2 g* ^* WIE 8.01 P# V) ^1 v' z8 H6 _' _2 S
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
) _( n/ `4 [; f% Q
$ y3 _4 G- a+ R# p5 ?( G) mIE 7.0
+ Y1 b% b3 `" C5 x4 s5 u! M% |5 iUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
8 _) h* I" g4 U. C) k. Y6 F& X
& h7 o/ N- M- k/ O! ^4 NIE 6.0" d  o& g/ F$ K; R
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)* l# r0 u+ X" A' S% Y

( g2 i% E' q4 e; G( Q* FFirefox 4.0.1 – MAC% {. K0 P, a) [6 p0 S8 F
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1  [6 L4 T6 K7 P
) X$ g; G. a, e
Firefox 4.0.1 – Windows
) R" \  C' O6 M  K6 ^. \User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.13 g4 e9 X! }1 Y8 X

1 \6 M7 U/ g. K$ M) o# ]; d# GOpera 11.11 – MAC) O. {8 `3 e. d1 {$ K' Y
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
+ |8 t3 E* G8 c$ A, v
. {* c" q' F) m8 Q& ?1 W  SOpera 11.11 – Windows
& Z: h% P+ f3 d0 b' O, ?User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
( P' I! W( W( N( t' u# V+ u7 L2 K$ a3 l
, S! R- B, T) {7 m* `0 ~$ CChrome 17.0 – MAC
# w) k' W- A" t; YUser-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
- n4 ?9 x; s2 jUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
/ X- w4 y. W  f! c* S
# q0 Q9 }) d8 P9 M- fTT2 E- H) a3 c* {: ~$ s8 Z; h
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)8 V4 {2 ^% R, G# s7 w

! G9 Y3 Q9 E! l; M; h: SThe World 2.x" b5 M/ y3 Z6 `% V8 i) ?1 a" {
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)# x! ?% L/ ?8 \+ p- x5 W$ |1 m; h
; \+ L$ j" R* X% E! t- h2 j
The World 3.x
3 R$ f/ [( f. RUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
; ?' w# e5 T# s: }# i6 D) R; I/ ~; z) N# }& w+ Z5 ~
搜狗浏览器 1.x
1 A) M/ O9 P$ e  _1 h6 K, _* \3 N8 [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)3 x  d, l: q! _  j& I! @' K

& o. f/ {1 O* g7 D360SE( }) b/ I; U* [- W/ {7 k7 v
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
" Y6 a( j4 K% x; a5 D2 W; w' [% Q4 m# M
Avant: o& }* |+ L) C  b' ~% ~8 v/ P
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)2 ~  v( p& V2 ]! a# F

% b5 }# \: T7 \, {Green Browser
/ `! B( D6 E( N; e" ^0 pUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone8 F4 t+ M* R& ~
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
7 _! F& ]% S6 X) q+ a: m9 o* J8 \( r" D& h3 ]0 H6 E6 q; A- @
safari iOS 4.33 – iPod Touch
% f: ]1 y+ m* _& M& X1 Z- C- sUser-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* u7 I' C. b% X! V

' j( [" u( \  ?- d+ M& \safari iOS 4.33 – iPad
  D, ^: P+ e# D3 AUser-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, A0 T  r2 D6 k  E) t

# P0 V; Y" o0 R0 t" o6 t: }% ^8 Y' [Android N1
3 Q# m- [' f9 O# T7 ?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
, f; n, ~$ V+ v& M, u+ f9 J+ C5 \% y& m6 \$ _( k3 `0 I
Android QQ For android
# o- A$ G0 ]$ K; B/ dUser-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 \" p6 a& A, i7 T* r6 j+ r# z
6 @9 v, O  Z+ C1 j1 r" v$ d: _1 j0 yAndroid Opera Mobile
) t* m/ l4 @1 ]0 UUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.107 O" V. O' o% ?  O, L( m
) s: Q3 q4 }4 t" u
Android Pad Moto Xoom3 A: }1 T; q  A0 b) K, O% \
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
# b# Q% L" f, X9 m6 c* U; w8 \
5 R8 z' b: j2 x0 P2 l) jBlackBerry, O, f& R) u* K7 A! d% z  @
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+
; o- S7 l+ J8 ~
6 E/ r8 Y7 h, O# e% n( gWebOS HP Touchpad3 v2 ?8 {& s- E4 D  h
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.09 N0 i- w0 [. V  a, r2 T; T

! S( Q6 `/ @4 D: v5 N" V. pNokia N97# \# v# e; m" b2 k; s" ]: @/ Q
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% `1 B& P  K0 u- A
3 E* X/ d! a1 r! V
Windows Phone Mango6 H/ n! i6 m6 X7 [2 t
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
9 v0 R7 Y5 {: v8 @4 n7 x
- x1 L* o: N3 @UC标准1 [) g' S8 F, x, T
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9992 }: N4 X- O$ e$ V8 Y4 g, C* w
( a. \% @( I" v% @, R0 U. I
UCOpenwave
# c3 `1 o! Z2 C2 IUser-Agent: Openwave/ UCWEB7.0.2.37/28/999' h- F, U$ j9 m; [* P, R2 C. e
6 s2 {7 T$ ]" q& Y4 V
UC Opera
( K- ^$ H( a$ t5 j# F5 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
互联网安全