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

  {- x  f6 ^- B+ [! n4 ?5 D


. P- r8 p. M/ v6 v6 h* J6 F

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

3 h/ P- Q8 U' m

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: E, Q( n% w9 X

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


. d( m/ p7 R) I: t$ U5 W5 k4 `" r3 @5 z+ d# ^$ a; f! E/ ~

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC" T2 f2 l2 N" r$ k" M) J6 V! S
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% w- p; _' X) `3 \2 J' ^7 x6 v0 o
, n  |0 v: E  ?8 e3 _0 ~
safari 5.1 – Windows
5 O3 ~1 q( O7 ~& P6 A( L! Y: p& u1 jUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
! d, P# E* L: ?; Z  J. k. ]
' O/ S: x, W; K5 \( I5 v) N, NIE 9.0
5 \+ u4 g) W2 H/ ~User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
. F1 A8 x4 M- v8 f; H0 d) c1 {2 q" f
IE 8.0
3 g( F% I4 `% K% AUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
! K- d9 L0 f/ H1 r7 J. i/ t* F, ~, b3 z. w! W5 F, i
IE 7.06 e* l! i6 Q. p- H- O* C
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)+ ~! ~: [" M  I2 J
3 Q0 n0 V6 {# y- ?! Q, U3 ]
IE 6.0- p1 F6 d8 v% S4 k! c9 [& z
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
: e; {, k/ W1 z! M6 B5 \+ M. s, N/ `! w: ]
Firefox 4.0.1 – MAC# T  G4 y6 E, N3 Q
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1. F2 ~* y; w& v7 s& t& I6 g. j& y/ b  y: s

6 k8 f$ u( p- [  MFirefox 4.0.1 – Windows
/ a: `. S) X' J, K0 X( f  yUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
- r# E- I4 b, S" ?& i3 `+ x7 b5 K" m% v, j* K& m: |
Opera 11.11 – MAC+ u( p) I4 v- e' G
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
# ]: e: Q; V" @  W/ w; o" _3 O/ r- L
Opera 11.11 – Windows1 q& g( Y6 `, \5 ^0 n, X8 g
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
# `8 s" j0 ], _1 }4 d8 }$ D3 v0 f
Chrome 17.0 – MAC
: p- x/ L1 Z0 k( C# SUser-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
$ |) X' n- X7 vUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
6 u: H1 n  B9 P; F5 _
" X' O* w! Q7 I( xTT2 ~4 ?: z. _! F# Y9 L) K7 p8 {4 ^
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)7 v* k% |! d5 x1 i, B
9 z1 [0 I' @4 Y$ R, Q
The World 2.x. V- J! j2 L" ~% `) t) s
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
, Z9 g+ N0 G' B0 }  B5 K# Q5 I5 _+ w2 r1 t0 Y1 x& F3 w
The World 3.x
1 y  _- g, {; N. N: r- \' p! uUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
( _) W- i2 e$ {' T" Q+ e2 C3 X7 w- g& m* Q, Q" }
搜狗浏览器 1.x
6 @) X( \9 ~& x  n9 {* U8 kUser-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)- d2 i' d' I2 M# l: q- _/ ]1 o$ e

+ D$ P+ k! m$ \0 k360SE! t( P' E: ?$ p/ E9 n. H" h
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE); L2 V0 t; o9 P. h( K
7 I+ w  T* l# B/ U3 d+ f
Avant; W! E' |0 |& q0 c
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
/ |! x, p# x# p" {) H/ V1 {+ r+ r, C' v3 {9 ]' _
Green Browser
, Q( U0 [/ k+ A4 VUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
  D; I. Z0 j) Z2 b1 {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.52 ]/ N% K( h/ u( Q9 [
! ]# J2 b  g9 `! t; [* i
safari iOS 4.33 – iPod Touch
* W6 \5 z6 o3 R8 ^, F4 q/ W9 r; xUser-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
$ ?* z: r5 _4 t2 D
+ p) x3 x* M& S6 L% ?) D. _" Ssafari iOS 4.33 – iPad
0 u! o5 \* g) e% ~+ HUser-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
1 f/ X% x  c( J8 {$ g0 {
; w6 n1 J. k- Z9 n9 }0 f$ ?Android N1
( o% D) N, e6 ^8 aUser-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.15 G6 n, P# F$ O7 Z% L8 I
+ r# j2 D, k* M1 ]
Android QQ For android
9 k8 j* c# I" l) r9 s. NUser-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 h4 R; Y0 K9 T% {) F* ?+ {" j9 m7 }: j2 [' ]6 d; o! g
Android Opera Mobile
& S9 x2 m) \0 ~! M7 v6 z' ?User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.109 P0 `/ O* ^" O% [
& S  y4 Q5 \% _7 `* a( p
Android Pad Moto Xoom
& M* y% F$ [, g* k. [* eUser-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
+ M: n# X( e/ i: L" z3 q, g' |
$ V/ C- m0 G3 Y; O( o8 v" ], sBlackBerry
% y; W7 u; U4 O( H# S: dUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
: x! R2 H( W& X" w- |/ e
. ~4 x& s& W1 z9 D. d4 |! w: xWebOS HP Touchpad7 L  e+ S6 E: D/ @% |, m/ I: J/ a
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
/ e; B+ Q# j$ X/ ^
& J  O* {2 a1 gNokia N974 |% S2 a' j4 \  Y; P- i- a* V1 n: 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.18124
+ q2 C2 x5 i* w
. x( ?# T7 x& Y3 v0 r, ~8 PWindows Phone Mango
8 L, f* t( J6 M4 e+ y/ o( c- GUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)' x1 }8 t7 V4 I* V3 a

& v9 s0 ]- V- |3 U; b4 tUC标准3 P( K* d! J6 [9 V+ g1 _
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
! O5 G1 V0 g5 M1 r* b/ H. Z. A! j* b9 `- B: F# t0 w# J, Q
UCOpenwave
1 b7 O$ e4 ?8 I( g5 WUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
; p9 L6 ^$ o, E/ D) y/ C- l) i7 d, _% p$ y3 p; ~- I6 B
UC Opera" `  r: ^  P" L: K  V, y
User-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
互联网安全