$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.         ?>
复制代码
. q( e! V+ \9 A


# X7 N# [+ N4 R  r

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 w; t$ m0 u& y9 W! R- w) R# R

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

! r+ p4 ?. m, B" [2 p  n

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

5 F- _2 o7 D9 S  D: t6 Q# c3 |( Q& |

/ W. C: [) O) ]- ^+ T$ T

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC; v+ E% c, ]* ?
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! A! P' i4 S0 Q/ l7 E0 P$ D7 _

! F/ O" \- m! \$ K/ `safari 5.1 – Windows
) T0 V5 m6 J' ?( G% p0 I% yUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50* L3 p$ T8 V2 E

& D5 @0 _  R4 KIE 9.03 t* @7 w3 a) R  I
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
* ?7 S3 [- e; S+ o7 Y
/ X# x# v5 ~( vIE 8.0
/ j" Q$ i6 E1 |) w/ pUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)$ D- \& D( V9 i+ m
8 y. L  _1 i' I" i/ ^& _$ x1 L) B3 H
IE 7.0
* h0 N2 o5 h. V" p, gUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
6 b6 U5 M( I* K/ d* ^" Y8 g$ d) ^! j! n, g
IE 6.0
% e" Z! i8 d7 r/ n" V8 B9 {* \! XUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1); C% D4 C$ o! v7 U$ U

. y- \# a7 s0 h9 |4 a; ~( JFirefox 4.0.1 – MAC
4 Z" f/ u& i! y$ r' d, }User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1# Q4 X8 i& E8 L6 ~) y5 L
* q4 B3 C7 T1 A7 r
Firefox 4.0.1 – Windows1 K5 I3 ~* N& f/ z! a$ M  ~- ]. m: G
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
, R! a9 n7 Z! @* W5 l8 g: \1 M  X2 d2 G! e; m4 @3 c
Opera 11.11 – MAC6 V  u2 Y! C! E" s: l. _
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
  l7 {% r# w/ D  ], k  I6 H" ^+ ?
3 s! p4 M' s# O4 {Opera 11.11 – Windows6 i* I7 V, Q) c: _6 @
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
7 k/ o, C, h5 W9 Z, }: ^( R! y' W6 a. ~9 K
Chrome 17.0 – MAC
) F9 f4 @% R) n- [& S' pUser-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- X4 Y1 j& G' F- x4 c
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
# q1 {5 D0 N& A( i! t0 d) ]
  c; ^2 e+ b" D& S$ JTT
. z4 G# p7 @- O1 F/ fUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)* ]5 Y+ s  A2 u0 ~6 c
9 w/ x6 J* L7 S0 I) i( O# X2 t
The World 2.x
) R8 C5 l! H8 \/ zUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
% z0 q3 R- H& y( N
8 _+ {9 t2 y5 q/ G2 J% F* j1 vThe World 3.x
; M% ]0 h8 f/ ?9 o- kUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)* I' p; n6 f; I! {

2 y' A$ G, s$ q, M+ T! O+ \' v搜狗浏览器 1.x
: M1 |! B3 u& g/ l  b7 x4 s' TUser-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)6 a! R% J; k' h. f

1 C/ A: N  i6 N% u3 ?3 C: T4 g$ t% z360SE
4 v. e" e) y& k* G7 ]- ]User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
/ j8 r- b3 P8 P9 u: m6 T1 y& ~9 U( I4 J* `! M3 Q) T4 }: |
Avant( u2 R7 v0 {$ P0 X: N
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
" u( Q* O2 K5 X4 P) i. u
: t. E( q& {7 X2 d% BGreen Browser
( A* Y0 Y1 }) D4 I: i, K, h! ^User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
  A$ c3 Z7 T5 RUser-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 E& E( h# L% O6 y! a0 ~8 y, ^' G
# ]7 j. k# G) z# v3 U0 X. J) S" L
safari iOS 4.33 – iPod Touch
& f' A: Q* R5 h- U4 U  y9 hUser-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.51 K* V# T6 h* |: u: U& }

1 _2 j) N- h. y, ysafari iOS 4.33 – iPad) Q. y6 {$ s5 M
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) ]" V9 T. @2 U3 G  N# G
/ b" E' |# K1 S- n4 e0 @
Android N1
1 `: K6 \4 L& KUser-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
+ y2 O* F' a0 v# l% g1 T7 g5 E3 A5 E7 e1 T
Android QQ For android
  M. n1 g: ?" J) M# 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.15 V' L) S( W3 _/ W* f! \2 t

, T6 k1 L# O2 {0 z9 a3 `Android Opera Mobile5 _: R9 X  j: A3 B- F
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10) q" }) ?" M7 P% Y5 E

+ d' K) n/ L" B4 x1 r7 w. t9 }Android Pad Moto Xoom( Z+ o/ U& a2 Q" v& L# J; h' ]
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.132 h& Q4 g+ V# |* R1 ^

. M+ Z% n3 f0 GBlackBerry
/ W1 y; `2 R- ?  u2 [+ tUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
) L* Z3 P, C& C/ c" b1 N. _% a7 f& M
0 x% q% T& ^* b' EWebOS HP Touchpad; Y. B. f# d  l: 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: a/ A# z& H9 B

/ e4 x4 R4 z8 N; F6 q5 yNokia N97' ]' |; z4 U6 r
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.181245 C  J( E) z1 \- K& |) p0 D

( b: m$ @# [( k- g  O. eWindows Phone Mango
+ f: r. j  ~6 B* _User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
6 E( l4 k$ H6 K7 [( E) r0 A' Z. L6 k6 v  w2 t# m
UC标准
' c' B9 i& M" I/ a4 E& T$ bUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
( o8 l# `, b& F$ r1 _, N( g! u+ w" s' A
UCOpenwave
' r) W) M8 ]; ZUser-Agent: Openwave/ UCWEB7.0.2.37/28/999. O$ O2 N8 A( M6 S$ I) M4 X

% @& b' {0 f7 d2 ?" S  z% N3 p( rUC Opera
! r3 o9 I% e  z( IUser-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
互联网安全