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

8 q* q% n" G9 H6 o  ^4 p/ `9 G


: G; X% R* x. ~! i1 [" ?: N2 C$ z

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.         %>
复制代码
% j7 t$ G9 y8 G& q  F0 `

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.         }
复制代码
1 e/ ~, M. _; u% H3 E, e% e

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

( r+ s$ m, p& R/ D) Z6 U4 Y* W: E
" H( _' S  R: j0 \, W

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
( V* @/ D  f0 p* U* }6 GUser-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, X" O+ Q4 D/ f" V% j; C

' N; k/ L  B1 Q: |5 x0 k: [  Qsafari 5.1 – Windows% @. y4 C! `/ L9 [
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.500 e: a3 L% E9 Q
3 u7 ?7 ?8 I' @! `6 {, N' N4 ]+ `, \
IE 9.0, J2 D2 Z* g8 @7 k
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;$ p% u; R0 g; X) _2 S7 ^" f1 T
  V* h$ X" {0 ^7 P  M+ m' Z8 h
IE 8.0
' j$ P: A/ B5 Y0 e4 d9 Z6 `User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)6 C% f( L1 m5 h6 ?5 W1 A0 t5 z4 L

- z& j3 e/ s3 _$ z/ IIE 7.0
$ _7 }0 r2 d1 j) j3 m* a2 [! cUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)$ V$ w* ]4 I6 F. H9 M& J
$ Y1 r: c! _+ V% l1 f0 s
IE 6.0, z3 D& M' Q/ G' h9 V
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)& v1 k9 Z0 i# n
" E( _$ h$ K- x  X2 D1 z9 S* a
Firefox 4.0.1 – MAC/ C1 P) z5 k2 R) H+ A
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
# b4 {* ?; i: R  \& j, A4 E1 [6 o! }& Q: |' i+ Q$ b! b
Firefox 4.0.1 – Windows! b4 p# S0 j3 T. I- [2 Y; K
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
) }; h/ R' H; h% m" @8 n
2 q/ t2 x( c- s6 C3 ?9 d* {Opera 11.11 – MAC
. w3 C" D, L! u  TUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.114 S& [4 q* ?/ m2 ?- C% |- d
. r( g! u; s% S4 m' ^
Opera 11.11 – Windows
! N& X( S* i. c7 Q; ~/ LUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
- Y! ?" D; E! G6 o, `0 v2 u' \4 B$ r% A& P: x& P, P
Chrome 17.0 – MAC! z3 y: ^" Z& M2 a
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、国产浏览器

Maxthon3 c$ a* y5 Q/ F9 F$ [& Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
) v4 f4 M( n& y; O. c1 ~- t
- a% R% N8 a; R& f5 h5 wTT1 b# E7 n$ z, T
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
, N0 T3 f' ~! W4 X6 p9 z5 M) O
0 k- b9 d* Q4 UThe World 2.x
3 \1 S  D8 N5 f, Y, |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)* c- I2 W2 I! ]
/ F7 z# n  K4 w" i2 Y. x
The World 3.x$ F8 t9 V% |  [. B( M' R3 a$ L
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)2 S) U# X/ B% d% A+ B
8 v% l( }! C, P0 I+ o" S* X
搜狗浏览器 1.x
% a' T" L5 ]1 l; }  YUser-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 S1 W% A2 p* V+ Z) @- l# O6 Z

9 N: f! Z2 a& H& }* S2 X360SE
3 d5 m4 |. }+ d! d, d2 u2 y8 y) mUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)& c5 x* R1 d* T

/ O, A6 N- D8 o& Y1 P9 `Avant
5 m  n* r& q" L' q6 kUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
  V; v1 W: P; |2 Q" q5 P: G( A  r/ f& r$ m9 q
Green Browser
/ x, @* b7 I7 o; _User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
+ T* ^; H# _; _; JUser-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
  g5 W; o7 c4 @% V" U1 |, @$ U$ p1 b1 J
safari iOS 4.33 – iPod Touch: H8 n7 q  M) W  g/ {
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
% p) Z7 V- ]* G! N+ O+ C) }) t& I5 A, i3 f* O, l% Z
safari iOS 4.33 – iPad
. M4 n  Z& S! ]3 GUser-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
% o- @+ S* M4 O! P! l2 _2 D. r/ ?' `6 _
Android N1  A. E7 [. T. k
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
' O0 [) B3 H- r3 p; A6 D6 b
; J- i) H/ u) w1 e2 v# Z$ `Android QQ For android
" W- [- G! _6 V8 \4 b; _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
# h4 Z8 N; U4 w# X) B& I$ D8 B' }$ R5 u& m8 r1 G
Android Opera Mobile. d1 T& m3 f  K4 R# X6 B5 f
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.108 b5 }% O7 W5 i/ n% q
0 \0 w& J* n) r% X; E/ z' o
Android Pad Moto Xoom' k! {) P7 c1 _$ c/ {/ N
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( ^% }. w; U3 E+ l% }: D0 r3 R. Z
$ d: }7 u/ {3 Q% R9 P
BlackBerry: e6 Y( H3 |4 i  Z  y
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+3 r5 N8 j6 D1 r& S; V* a$ X

, `% \, |) K# J1 o( U+ V" eWebOS HP Touchpad' f2 u( Z3 f8 u/ y! z
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
% F# O$ G3 E, t7 r. ?
9 J9 `' A; X2 E5 INokia N97
2 L+ C- H9 m# F7 hUser-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.181244 t6 B% |( p' N! B5 C" A# l

& }. }0 R. L9 |1 i* {, J3 \! c8 x8 qWindows Phone Mango
* c4 x! Z7 d4 a. N4 q( H  f5 dUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)0 U6 N) Z9 h( Z) w0 \6 ?  W

( S; p: `1 \! S9 q! E& ~2 aUC标准
! P. p" W$ M7 L0 f# RUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
2 P0 _, K3 O3 B) h$ c/ w$ j
% l7 C; d% v2 u8 `9 {$ ]UCOpenwave: o: r+ D  e% i. F) [1 Z
User-Agent: Openwave/ UCWEB7.0.2.37/28/9991 Z' _& Y  b& ^2 h/ L
, T% @7 r: l/ j6 q
UC Opera
& n0 U; _1 G$ t. }User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

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

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全