$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.         ?>
复制代码
; t) D$ O- [3 L+ o


% t, _! u0 ^  E/ _  i$ I( n

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

' n3 }3 I2 g4 l3 |/ p. b5 D9 j

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.         }
复制代码
$ k0 o8 Q9 c* v

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


' s- e3 `' d; _8 \! Z! z3 }
8 }1 j8 M$ N, z

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC$ F( I" i2 ~/ P3 P' a: R
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.509 o$ M4 I; E' i
/ [. [' n9 r6 e; _
safari 5.1 – Windows
6 f% ]& _. D4 d6 s1 R" M. EUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
- ~+ V* r: M  D- |+ m; f
! T6 c- H; G1 [5 T5 |IE 9.02 c) G2 I! y0 E: @1 N+ O+ T6 x
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
( a, U" g' M0 x1 ^' a; j5 i9 R. G6 _
IE 8.09 v/ T8 a1 n9 J; @- B! x
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
3 \/ e7 {  s3 P4 R6 S) R
! a9 j" Y" _+ U" G4 g8 v" ^; fIE 7.0
) v6 j0 Y: w& b9 ~8 ZUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)7 P* X' A' t6 U

; h2 `! N0 q+ LIE 6.0
, x. ^% n4 \4 y( C0 {& V# [1 lUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)1 O& p8 v4 o& _/ Q0 M
0 b: [' A1 @# f  I! M9 l' @
Firefox 4.0.1 – MAC1 W- w1 A' e' u2 Q# z' ~
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
& {# E' ]7 y: @
9 J  X  k! r4 D, w+ s: D# V  HFirefox 4.0.1 – Windows% g7 \# \, J' }( V$ n/ t* T
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1* O* |1 u* q4 |  R0 L' |
& C. J) n6 q$ t) N' p2 _7 B
Opera 11.11 – MAC
3 I9 @9 Q/ I0 y4 V1 P: tUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11, X& m3 u$ Z+ u6 J: z. ?9 \

1 g8 C* M8 o: ]9 F6 eOpera 11.11 – Windows: M. v$ S+ F: I7 S5 m
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11& E6 g2 g; t" M# L/ i
1 F) @- x1 l+ [0 \% |6 P
Chrome 17.0 – MAC
1 Q1 c; z8 D9 p: h  uUser-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
6 d( C, m5 I" Y  Z8 ^3 SUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
: b' F/ \3 H3 \8 i; X( Z) d. a1 ^
TT9 _# l9 l' G$ r$ s5 C
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
9 L! i) K6 B( [, Z7 D. j- N: L6 S0 U+ V: O+ X# s" m: T# `
The World 2.x
* R. S! `: T( l, j, N, K+ z7 k7 OUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)4 t: |) I# X: `
5 ^$ E* t' j3 B. j+ N
The World 3.x& [; Y2 v$ h. I5 d1 _" n  i/ V
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
- _  k3 v* Q7 B, r+ z) z" |* z  D" i
搜狗浏览器 1.x
1 c! l+ C4 s; ]: M+ e8 lUser-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)$ e* K. h, M! W0 a! a5 P

) |. J; o: |& G# B360SE
# b7 l5 e! z. @7 \User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
! e7 l6 q# W$ M4 y) V5 s6 O& {/ Q
Avant
& \. F. V2 J5 z4 A1 qUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
0 E9 q/ ~2 m, _
  Z# T( j& }+ t/ A" r2 qGreen Browser
( S0 a$ h: \) ~User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
2 L* M+ ?. S& e; }( WUser-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) J( ~' u. m$ ^8 V

* y) {5 {/ [2 N9 R. j) vsafari iOS 4.33 – iPod Touch; E9 r# y! @( i6 i! w- C! Y
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
; B# u! B# J+ a8 w# t7 f# e6 h+ I1 r) |5 W
safari iOS 4.33 – iPad0 O& X, {- R9 @5 m# u: _: k3 `
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.55 Q4 P" U6 s0 s) e/ ?" P

$ }, Z& L( J* u1 c9 r8 C+ EAndroid N1( t- s: p1 p, B& C- n0 h9 t& |/ Z
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* A, X" P- N+ V9 S9 e% U
  K, p7 U6 a7 E/ m8 X
Android QQ For android
6 A! Q# l7 r' f+ e$ B) YUser-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, a# z5 y3 M7 z

; s) n  u; [- F+ q! X1 `, D+ n8 mAndroid Opera Mobile  k3 r0 D. ~- v0 k, f
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.100 m( H6 Q; Q* y7 h

$ q, w2 [; H- t' F8 XAndroid Pad Moto Xoom5 \0 s6 t- D3 p0 v; h6 x
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
. w  ?, {  n3 W6 J( {' n
8 L! q& e% d+ V* Y3 o  cBlackBerry
  Z3 Q; h, @6 h, Z; A2 vUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
+ Q/ B: f$ \; J2 o9 R6 D+ w$ [% Z2 M! U( @1 S
WebOS HP Touchpad0 P, e, ?0 U, g3 \
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! `* _: x9 j" S2 {$ |- v& t' ^7 w2 ^, W
+ L/ q( V; [! s/ z, m7 W9 X) w, e3 B
Nokia N97
7 Y6 L+ n8 e& U6 q' XUser-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 b9 N& o, E3 e* M& w- P. H: h1 E4 p% f! g( S0 g  Y/ d
Windows Phone Mango; ~5 V" |+ L' F* b) E6 m# i
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
3 n! E3 r$ E0 B. g* P% l
3 Z4 k3 i) e9 \' j0 D$ uUC标准: A' s$ L6 [$ a
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
0 `* i3 s+ L; R2 @& P& E2 X2 {; U3 u& z; h% X+ @2 _8 u( P# ?- p+ Y! O; y
UCOpenwave
4 R7 C9 `" [7 O: lUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
6 p; n) n7 d$ H  y. ]1 d7 q' b  e& I! q
UC Opera) o) E8 E: m* M
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
互联网安全