$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  D+ F/ q- Q! [


4 Z" {4 C9 R. b- 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.         %>
复制代码
5 h& l4 f' z2 p# t5 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.         }
复制代码
9 @" d9 R2 @, v. ?5 L8 d1 W

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

% O$ ~$ E# r9 Q7 ~* w) `
4 N! a4 ~* g$ H: a. h( {' r

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC2 v6 }% L" u& f* n/ y3 u0 [
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
- j& |7 p' X* u6 c+ ?
* k4 F8 [* l% I7 z+ W1 ^safari 5.1 – Windows8 n* q3 l+ V6 N$ i
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
5 O/ l' x& }4 _1 n% `8 b; p3 m: |' B8 x7 \, h1 o& P
IE 9.06 k8 ^& C+ n, i" J
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;. d1 H7 V) p1 |: C% z& ^: Y

/ @7 M  X) f% B! EIE 8.0
1 A. Y- b3 i( A# _2 `User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
) g. F7 W& s# _% m* r, H3 h2 I$ g4 f: o4 a, |
IE 7.0
) r2 i' P+ i9 k- ^' ]% J( U0 JUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
6 \9 `1 |3 l" L9 ^' z" G8 l' g" W& {( K
0 P$ f; f9 }; r( F" O" u$ ]; uIE 6.01 w6 |# f+ X2 ?# l
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)& e' n% R) c" s3 d) e) k
* N/ q% F( A2 l; o( U( i  b
Firefox 4.0.1 – MAC
, B1 u4 i5 {0 t3 R1 |" c' xUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
0 A4 T( O, t2 R5 }
7 G2 D- F% p! o0 yFirefox 4.0.1 – Windows3 I7 J$ S5 l6 ^# b5 K" o5 f$ w
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
' \% k# W9 p1 L# y& M  @3 `$ r) z" y
Opera 11.11 – MAC
: Y, K  ~2 {8 B" wUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
9 @7 s- R) ]: b/ w' z
4 I0 ^7 R' @* t" v. }0 v- w% sOpera 11.11 – Windows
  _0 ?3 J" v4 o) BUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11, ^! ~: C2 C$ t8 n
% Y* p7 r% {$ ?! ]
Chrome 17.0 – MAC+ u9 n$ P/ [4 k0 \- f1 }7 @1 a* g
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
- D7 R( i2 ]! _: ^( e1 SUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)) |% {6 T- f- f; W& l
& o/ z( r' s; l; f
TT2 r$ W7 }- H. m! U. y" b! w
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
2 e1 s" S7 r+ d, Z4 _5 i  b
, ^* T! ?9 o- u( g( M4 a/ o, h! q8 F1 IThe World 2.x5 e# z7 b  y( P) c
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)' Z, d2 D# V( D9 ]: y- ]8 f
% L& s5 s/ |& h9 S  ~1 a8 e8 i
The World 3.x
4 c+ \  {6 X1 I3 ~. Y- vUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
4 ~' q4 s7 D2 n  U0 k+ _  v4 j: {) L: p' o$ K5 s" r0 _; G5 O
搜狗浏览器 1.x. g( R& q! k. }( r: p' l) H
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)% }4 \- w4 M* i9 c9 T

1 p/ u1 n( F0 n7 G- c' g9 X; B360SE
3 }2 \* V3 b2 v  AUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)0 |& ^8 c+ e& T
& u5 B% q$ |: [) j+ y$ Z( c
Avant% K: m9 I( G, _0 f
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
! X- g- C, a% o
$ o- U3 W1 L0 a3 }) R0 W1 dGreen Browser
& ^$ v7 `4 B4 l# q4 IUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone3 i! x) A* {3 e
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. t1 S3 s3 c5 T0 o+ D5 |4 U& _
5 C% D  J. o0 G, S, [
safari iOS 4.33 – iPod Touch
2 u1 e1 k# z- ]7 P8 I& E; oUser-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.56 T; p9 d! n: B- z

* r' x& U) T* W+ z$ _* u, ], ksafari iOS 4.33 – iPad, @  k& v( C: i1 l
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% Y3 Q& Y" g9 A- [2 q0 f# E
! \9 f% X& h$ C9 F
Android N1: f+ E) p6 |/ B( e3 n# i0 E9 Y& {
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% G' `$ B" @9 M2 `. `
2 w" b  t8 n' M( o7 {: k7 g" H+ S
Android QQ For android+ ?) V6 r: C$ j7 m% F8 S- S' i% z" F" {
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
* B6 ^# Z8 {5 x1 v4 A0 k& Q9 t6 b& A2 Z% j5 \; P. A5 h( X
Android Opera Mobile2 {, a" y  I3 ], }4 k
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
0 z+ f- C" z! ~. J& l; P4 t1 [
$ x" i+ {7 J) |" g8 t) I. D; JAndroid Pad Moto Xoom
* j8 p6 l. X, D! R3 v3 B7 HUser-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
/ U  d$ a1 W& I2 U# r. ]
. j+ C8 R0 P" C$ V" [2 {( CBlackBerry$ j; n' g; n' O) i6 Q
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+4 n% s/ Y& K* Z/ ?4 s% m
" I: n3 u& k/ O+ s
WebOS HP Touchpad4 h! \* N& x/ W& B6 t0 X
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/ p1 d3 E* I. V0 c. E* ]0 M" J

& T, u) |2 r* q0 sNokia N970 }% i. u/ U. ^
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 X- i% T+ p, R  p0 w
- v3 Y: {( k( ?# M0 p" A! IWindows Phone Mango
! }; V- h9 [4 Q9 G  ^' NUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
+ z) p% L6 ^- v9 T% [2 u. N
- p( Y* @( F& {) g& d( r; kUC标准
0 U2 [! |  `3 X( bUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
4 F7 `1 `& H  d2 ]6 T# P- r9 {
, Z5 X9 F" ~9 p" @# l9 BUCOpenwave
  V+ _5 b4 ~' q1 f( F5 r' }User-Agent: Openwave/ UCWEB7.0.2.37/28/999
$ @6 C2 T' _5 a$ G: H, f. f% D) B' F% u" G
UC Opera4 B" U0 ?4 A2 Z+ g* l3 ]2 J
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
互联网安全