Board logo

标题: [其它] 分享php/asp/asp.net aspx判断百度PC端和移动端蜘蛛的源代码 [打印本页]

作者: jfx    时间: 2016-8-30 17:38     标题: 分享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.         ?>
复制代码
5 ~( S5 J4 q. U* m) s) W


6 u4 V5 v% k) N8 R9 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.         %>
复制代码

6 {" P' E- [7 v7 T: e

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.         }
复制代码
  }( V" `+ ?- V* c  W

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

) p) u  f$ S* K" T( \& @( U

6 O) E5 v& S1 Z

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
/ n+ a( |5 E3 x" i7 n# a6 rUser-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.507 O$ [; S  X3 @( N/ A) T) d
' N' Z2 U  A9 i. a
safari 5.1 – Windows/ _( c; |$ P. s0 `, T: g6 e
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/ b+ c4 f  _! i
8 p  u% N2 S$ {+ l0 m; ~* G( w/ P- K
IE 9.0
. U2 J" `! l9 o3 S+ T$ c( r% U+ jUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;1 F' S4 d! Q! R( X
0 g7 Q) L8 f; O5 D$ v
IE 8.0
$ @4 [4 T  B' w% k5 E; U5 ?! G5 \User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)2 i  ~3 D1 Z  G  u4 q, Z
9 M" `: ^" y7 R: r: P
IE 7.0
8 e2 E! ~4 A& l: O% Y: O7 |2 KUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
7 h7 w% Q# t; W) u; L+ ~
4 N* Y) V6 k0 C& yIE 6.0" T" X6 C% g) M/ |/ z
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1). |1 X9 _; x( @& ]

# t5 `& R* b$ G8 x7 d* E1 \' D) I/ nFirefox 4.0.1 – MAC
/ b; b+ r" Y9 B7 yUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
6 Y. P* D8 |6 N$ S: W! `1 f8 A( J0 v& i$ L" q; H# V0 D0 a
Firefox 4.0.1 – Windows. J3 D, J7 D7 C9 V/ \5 N. c
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.12 x# ?9 n9 U8 q  n; ~6 X) C6 B
1 J: [. w( v2 _
Opera 11.11 – MAC
7 |% z/ s  v7 m% VUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11- V( G+ y5 Q# c0 b9 x! }
" a2 |0 @  ?- s+ M' A2 h7 `  E6 b- P& F
Opera 11.11 – Windows& b) f2 V# c! s" ]2 {# J8 n3 u
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.112 Q- L- U: c' J. a# B+ Q3 _4 \* \$ ?

# R7 i. Z+ s- y; F& j3 e  ^# X0 ]7 UChrome 17.0 – MAC: }; ?% w' m) z$ m1 }( Z# e9 ?: ^1 h
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
3 J9 z5 E" j6 j6 E3 Y( d; A- O% \User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)% C* h! \1 W  J; _4 N: f- P

! p8 F6 o1 W4 {2 F( b. JTT
; \5 ~0 T# i6 \' N6 N6 q. \User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)7 @5 ?1 \' [, P0 ~

7 H0 }- }5 s& R8 Y$ K0 v! k+ \The World 2.x6 x) |! W' l" r& p  I
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
  S  V* o0 P+ U* F7 w8 d6 N" }) @  ~" l1 Y! Q# B
The World 3.x
1 b7 E7 T* R  k& Z; OUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)9 b  u% M9 p* v

% P2 h2 x- r1 ?+ a- A% a, i; G搜狗浏览器 1.x1 e: c. k7 c* e! f) ?
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)
: R7 `" ^+ Y+ x$ b, m. R/ \) a! R5 u, I7 i5 U2 D8 e
360SE
" K  K7 x' L4 b6 L2 J- m, B3 BUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)9 I& x/ \5 |3 w" o
* {3 l5 j- J" d9 j5 w" a
Avant( }& n4 M, W* B/ {* Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
0 a8 f1 U6 \1 c+ U. u7 X' r9 {, B4 n- m
Green Browser: C5 d5 C: @6 }8 e
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone1 Q# u& W6 o& X9 P( U
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+ M+ m2 m7 V, X* ^

- J  H$ x7 F# Z, tsafari iOS 4.33 – iPod Touch2 M* I6 @* D9 b* ~2 f4 P3 k: }
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
3 l0 {3 t6 I4 ~! D3 u/ P+ f$ I7 [& q$ K0 h' p& u; P+ r( p
safari iOS 4.33 – iPad* e7 ]/ n6 B0 V3 X+ a0 |& n1 `; X
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
5 @" _) Z, q/ c/ ]9 U
# ?- {3 J; u4 _Android N1
2 {, I# ~' g4 I# b1 g: EUser-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
3 b' |# P# S0 f: N( A" n8 G5 }% F5 z3 J/ s  [
Android QQ For android# K7 m7 ]: {/ m7 j+ u; H5 |
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
* B! f3 ^4 C8 H3 Z' f& `+ Y1 [/ F  m5 X% H7 L7 k2 ?
Android Opera Mobile) T. K: q) B4 w; k" g2 p
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
. x5 y% ~( r/ H# k# M. n) Q' S4 O& m( c1 K5 m9 Q. V& ]
Android Pad Moto Xoom# q9 G8 ^0 P% H" e
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
5 _& {! I$ }3 }9 L; c2 Q0 D5 N4 Y- O' u
BlackBerry
# H2 r6 [2 |1 Y) GUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
6 y$ k# g2 j9 e
! Y+ \3 b# v4 p2 `( k$ G1 P- AWebOS HP Touchpad
) |' ^$ a6 f8 CUser-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.03 s: [- B7 U2 [. ^6 ?

1 v1 R' H! W) U! ~+ I5 lNokia N97+ m/ r' ^$ r6 u6 l6 K: 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.18124+ d+ {: B/ ]* G$ }7 G

& ^' t2 I+ z. G+ Z0 TWindows Phone Mango
4 G; |4 ~, v  L3 hUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
. L/ L' U2 B) k$ o0 \  k, S: y
1 G8 R; w) M/ S7 U, T/ z$ C5 r1 xUC标准
1 k# b3 Z2 w* E% T: S/ EUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999( \6 b: j7 y/ v9 R* A) T
% T6 y( y6 I. r, Y# `6 V
UCOpenwave: P6 t. P4 a$ w- Z* V- x
User-Agent: Openwave/ UCWEB7.0.2.37/28/9999 t2 J  W9 l  C- G
* Y- V! G) O- A3 n
UC Opera
$ c" D5 `5 i# D6 Z% M/ X1 a" S2 XUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

参考: http://www.webkaka.com/tutorial/zhanzhang/2015/060421/






欢迎光临 捷飞网络论坛 (http://bbs.fjbjdd.com/) Powered by Discuz! 7.2