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

3 D) h( v$ F; D

. a; ]! [4 O1 L- M4 g- q

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.         %>
复制代码
: S, G+ f& \' @0 {

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 L" g4 V* n% X; W

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


. T1 r: U1 M; \
1 w  X" g8 A, t* f4 B' I

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC, M3 f6 @- e& r3 `% O
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.501 n/ P1 W6 g' \( A# C/ {

# I2 _" r. ]" y! L6 A, g4 [; N8 Fsafari 5.1 – Windows. Y7 [+ f8 G$ w  S5 R
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
; z: \3 n* ^- |( N( T3 n( \' _2 Y" Z, I$ z
IE 9.0
0 U* ]5 b" z: X) }3 q" e3 ^User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
. Z" W- p: S: z# z: `  y9 C
1 e5 Z% D& m! l5 `IE 8.0' }- T9 @& Z( g6 U& w1 M6 ^
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
% ?% T/ r: ^$ j, R, E4 B* @& p% N) _0 P8 U) ]! M+ v
IE 7.01 j$ d- i, _5 |
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)& G8 J5 N9 r7 X8 U0 X

9 f: g+ i/ W: c0 |$ c; FIE 6.0
! [* k8 p0 s4 C% p! fUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
) a8 v: C5 Y  A5 l9 H
+ x% a- r" U* w" g1 V4 |8 ~Firefox 4.0.1 – MAC
9 c# o* }9 r' Z0 Y4 ]$ O$ rUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
' f" ]/ X7 a0 z/ {8 ~
. V6 F7 K  N& s) wFirefox 4.0.1 – Windows
, B1 D/ Y( `& ]  s: GUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.19 x8 B- H  m9 m! u

0 z& [1 K% p9 a; _7 ~" J7 n/ |8 sOpera 11.11 – MAC
* H: p4 @  L, x. p# BUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.115 T/ Z1 X0 I. }" n

; Q4 D& S% @0 }0 p  y/ `3 B. WOpera 11.11 – Windows
- o, ?  t8 I2 X( G: yUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11: _3 i/ T  [) }  t

# ~8 R* k- A, P' M2 c/ oChrome 17.0 – MAC
# V! v8 y7 ^5 @8 i: ]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( M5 k/ F$ d. F: ]( |  [  y& a
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
/ w+ v# s2 D0 O* T% d
. _/ o! f. b4 t: N+ P9 \' eTT
2 O4 {# V0 c4 @: t- R, H5 KUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
' i+ m0 g3 Q- U& v. F1 q3 k, Q1 m! S/ c( m) c
The World 2.x8 g1 k: j, l3 u  D: s: A
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
$ r8 D. d5 n1 y, p7 x2 y# }7 f
) |* p! o: B# q3 hThe World 3.x$ h8 _6 z9 I. @& b
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)) K- C3 X% |; {/ }
! x4 J2 }, ^/ U* M' G
搜狗浏览器 1.x
; X/ n. x5 k# u" L3 t0 W! p; NUser-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)
# `3 {$ }7 C4 S: [# b; l& m3 W9 O: e
360SE# K5 R2 q+ Y) X4 _5 G$ c  o  X8 c
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)3 y3 h9 k/ [) N! v
6 w0 i1 j( o7 R2 z- u# a9 K: s# a9 F. f
Avant
5 W4 s- U/ b, d2 YUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
- B: a! {/ r% ?1 w7 S0 n8 T  N- C2 }! G
Green Browser" G# K' x: B+ M# I" G( G/ f! p% B
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone8 E+ u( j/ [0 w- {% N3 I) b+ j9 d
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
& `9 C, o# U9 J- ]9 }
, ?- A* Z4 a9 @, lsafari iOS 4.33 – iPod Touch
% w) h6 V8 x  `" V( cUser-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
9 X" O9 b, b* z$ c1 ~1 M% R7 I$ }8 O) }% B: N# H# k9 \
safari iOS 4.33 – iPad
5 u3 l/ g* ]/ A7 C9 k  H+ eUser-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- S  ^1 T$ Q2 ]
4 J5 B& j% ]. N2 G0 @& u" w+ Q# {. x
Android N1
; R+ E" ?* _: K! vUser-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.17 t: f# h8 T& L* T: E* @" S) p
  }, S+ ~! b% e0 |
Android QQ For android
: E  w. K4 L8 B) h4 ~* |% AUser-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' N* X9 z- ~' Q" w/ D

2 P2 V1 A# y4 V* p- B2 K8 O/ zAndroid Opera Mobile
* W0 Z) q2 ^6 r% g# z) eUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.104 g+ E$ n- R- m+ \1 ?

4 |+ ^8 o* M8 o# O; N) c3 yAndroid Pad Moto Xoom9 ~  z( q" y# u1 g
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
$ K4 N" \, I& t6 s7 @- H2 N/ H( c3 m1 J8 @$ i; O
BlackBerry. w7 T5 y) ~6 Z1 x
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+9 G: y6 m' H, l( D5 q) [/ M: G
" R7 x0 i" |( Q' E
WebOS HP Touchpad- V$ E7 q& G8 ]( 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
4 B* s6 Y+ |. U! c1 H4 X6 ~/ h9 @/ f- c+ i; k, J
Nokia N97* x' \3 \  w3 ]! J9 T
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
" ?7 [. @1 R6 A# O% t' k% k) i/ `! Q
4 V0 M1 `7 K- h" mWindows Phone Mango
* u% B( j7 b' [0 ?: dUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
' {7 ?$ ~0 q) I$ r% i
  s( [' n% y. |8 mUC标准
3 t; P- p; h3 m+ N2 f5 C* L( y+ pUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
) I9 }, F6 p: m' K5 j  q5 Q) D5 C7 F. x/ t
UCOpenwave! T5 p& Y1 `0 T3 C: m! o
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
: m) U2 ~& j# S3 R; J% C5 E
# F$ m( i$ P! NUC Opera: T9 Z1 U) w; o' N2 ]; ~# i; v0 A
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
互联网安全