$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.         ?>
复制代码
) A+ t+ \$ s. s- A


$ `+ _  X0 M4 l6 O: K" a

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.         %>
复制代码
0 `8 x9 P; L6 E6 C+ {

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

. q2 f1 J" s: ]$ j; J6 M

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


- N# a/ B) g$ p+ b$ C8 D1 k( j1 c6 ^6 g( D! b  j, q

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC( }7 t5 s3 J5 d; [5 ^9 E* P
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 r$ C+ H- z/ z3 ?0 u
1 \3 N" S# b% usafari 5.1 – Windows/ a( K. \; l. o* m2 S
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- q% e& q' F7 n" k. b* N) Z

7 l7 e+ }- i* s3 w0 |' O, S' I. VIE 9.0& `! r7 U5 R  k' N5 f2 B7 I
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
6 U. M  D# l, Q! r0 O# V3 t1 @$ K! [6 ?
IE 8.0
$ {, i& n7 Q" w9 L3 N9 xUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)! c# x) t1 @( J) h7 t' f. U! b9 Q' a

% z/ j' b) d  K& H" f& iIE 7.0
& M' E9 P- g+ o! PUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
3 W0 V  ]* L; ~4 v: S+ K
" B5 \, q+ D' }7 }3 zIE 6.0
2 K  V4 N: x/ X5 d2 y( jUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
, Y3 r9 S# U: r" G: b# I  P
6 I9 i+ v$ C4 }  `) D' _Firefox 4.0.1 – MAC
, C% z$ M7 L" j. {) X& l( ~User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1% }) C* F  c  f9 F7 G0 m0 p

; R) e4 n- D' S) }( Y  @, j6 hFirefox 4.0.1 – Windows
# _; ]% A9 I, A" F1 m1 BUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
2 G0 A! @$ I. b2 y6 w8 E" F- d. I# N0 j7 U. w0 B; h6 P0 I
Opera 11.11 – MAC, D2 K" W' H7 A5 t) r; o
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11) w9 |2 U8 H/ N. l) F7 p1 o

8 {3 M* c3 [) j0 i' {3 G; mOpera 11.11 – Windows( i& v' U' ?9 c/ ?
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
7 T+ ?5 y7 y" M0 ^: h
8 r# F/ B- @/ h) o& _Chrome 17.0 – MAC( E9 n7 `; M7 H. B
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
9 i0 X( p) \* N1 p6 uUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
% e0 ~. C0 ^! \% G  ^
  W% w, O- h9 u5 _% V* pTT
  z3 l. C) C3 g0 S- ?/ {0 JUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)2 ~9 c% q, y9 U8 |0 H9 ^

- B( w. f# r$ t/ W0 H; a& ZThe World 2.x
  m/ N' S6 T- _7 U1 _7 C# MUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1), k+ _+ C4 O  O4 X* H2 i/ _* |# m

  W5 x. Q7 y' a. H$ A' v/ GThe World 3.x+ g4 S9 ^$ T/ y, g/ s/ F6 m
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)( O' E5 p. R; C: m5 @3 ]8 J7 d& _% c
5 K2 p. e4 K/ S& f* }
搜狗浏览器 1.x( U2 U; [4 g. o# g
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)8 F3 R4 L" q9 o  B

2 ^- }+ Q. _. B7 ^: h. b9 g+ v360SE! a" z9 h  X6 z  m3 T! A
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
# B7 s! X" e9 L5 o  n! d( O3 a7 }" j$ X" Z" Q7 ^' ?9 Z1 D2 Q
Avant
) ^; O9 l* T+ [2 ^User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)* }& W2 L( B) ^  p: y) _9 R2 C
3 R: \- Y6 D' f- ^+ ~
Green Browser; H. Q% [$ ~2 ?! D7 w- A8 f
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone0 ]" N( B4 V5 p1 ], |2 K
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.58 d0 i0 c/ s! S6 U( g9 F
) a8 o5 f' `# c! W( D# }1 g
safari iOS 4.33 – iPod Touch5 f5 H! z$ |& R6 D
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& ?% ^0 U3 u8 n5 P! W
5 D- M. o1 h8 s8 k) V# \
safari iOS 4.33 – iPad4 d2 w3 i3 i" V5 u
User-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; G% N/ a" d/ U, y6 Z/ M
1 _8 a0 X, _0 d2 c7 P
Android N1
; F' Q( m" {& L1 s0 V) f8 Z" 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.18 }4 |& |* Z7 q- J2 n* Q) K

+ U& B/ @! i, ^; U3 Y9 oAndroid QQ For android
5 e0 u8 q4 X* P( {/ f9 v: TUser-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
4 L  l3 `! N5 Z0 j' H4 u8 I2 K" w# d  m7 E/ ?( L
Android Opera Mobile1 n3 o5 {- |- V, b3 c' Z
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
( {7 n/ E$ @3 O/ O+ ?' i# ]% b+ R* p% t$ ]. s& ]8 q2 B( K
Android Pad Moto Xoom
+ t" A% _6 R% j. N3 @9 |3 IUser-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
+ L4 R1 r8 m; z" F7 e9 m$ r) Y$ s' G' _
BlackBerry
1 C$ ?/ \2 @' R, CUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+" f! Q9 M$ j, o6 c* |

1 p0 P+ ?/ H3 w% XWebOS HP Touchpad# Y, d+ N2 i1 K" I7 l: M+ z' D
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$ k# U. j. A& }8 n3 s0 r

4 ?% P9 b; \0 e, n8 ]Nokia N97: q  {3 `9 v2 b8 e
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
; b$ X  ?3 m  \- y8 b- j1 V+ `+ _- J( @% O& L- B: s& \
Windows Phone Mango
" W! e# x: I6 {; y6 jUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)0 ^# F3 _: l3 J2 v( [8 E

, N9 U, ?6 l6 R8 u; _) AUC标准
$ E& [* ?4 c3 _9 s% s3 y- `User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999- _/ G6 [3 g) a- ^

+ u4 a# X9 T+ e$ HUCOpenwave
2 j5 m+ h- f- n! ZUser-Agent: Openwave/ UCWEB7.0.2.37/28/999$ n! g* h/ Y3 x7 q, o7 E

& u' Q! |3 _! P" ?9 ?/ k% FUC Opera# W% S& k$ K: Z  b
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
互联网安全