$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.         ?>
复制代码
; b. Y+ e* b6 X  Y


; \1 @' D3 Y# E9 S+ j, o/ r  I0 n1 t

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.         %>
复制代码
: q% h  U( w" ~& J! g1 A. w! v

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

- a2 N1 h' M5 l* k5 @

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

+ _  u, S( }  V1 I+ y; J& A5 t

! t- E  V& ^( C) q; }6 {

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
# x, Q2 H: s, i$ Z2 t+ ]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.507 G( h! I! I4 M3 B8 k

8 }; Z, h% s) [" s4 _safari 5.1 – Windows+ \+ r) {: p/ Z/ U
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' d: x3 g* v$ H  v9 I+ d' U6 F( P

. g% D, y& p1 G- D# k* QIE 9.03 |7 h2 @4 W9 z& v  n
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
4 y- N8 |9 U& W
4 d3 U$ V; p5 o6 \) WIE 8.0$ u- x2 f# z. l2 Y, I4 S. ?3 ~
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)( p/ O! q1 A; h. x( c
; V( i7 Q: z' I/ q9 ~( P" `. I
IE 7.0, i9 Y* ]! K0 f' _5 M
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
8 Y% y- Q$ F. T: D( U3 K3 p: Q3 o' K% J" n
IE 6.0( X  v3 M' f1 V9 P% y$ R9 U
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)  x+ T. u# ?6 v) F& V  A

' q- h& }# O% a$ [. C) X; l. G: ?Firefox 4.0.1 – MAC6 q5 g+ L9 \' g1 Z6 O$ e2 t8 t
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.15 N4 T% U+ K. T; d0 _

+ o) ?' J4 ~; ]/ P3 T1 R1 EFirefox 4.0.1 – Windows
$ a1 h* L/ J7 }+ }$ Y# g$ ZUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
  n+ g5 \) Z; f7 c; Z4 K. P
% D9 V) ]1 {8 C  f2 d7 t& `" cOpera 11.11 – MAC* S( p/ D, W& g" l+ R8 [
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
; U- _) k4 e7 U: W
9 z6 O4 G& n' [. w$ ^+ fOpera 11.11 – Windows
/ Q6 r1 Y2 Q* ?! Z6 L! ~& aUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
5 Z4 n% |5 J# J* N, e" q$ r# {- R" x8 W
Chrome 17.0 – MAC6 j! N2 u0 p! o- ^
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、国产浏览器

Maxthon2 L1 f: h% T+ \( V5 b2 ^
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
( o& h: p* D# ?( K, m# J
/ m/ D, n; \" f( B7 Z) t6 ~TT
, J; p8 {( `0 P" B, |1 `User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)' p$ j0 t  K7 t8 E

7 ?' X2 D- f2 tThe World 2.x
9 T3 f/ y# z  S5 G% rUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)2 K2 c( S' L* P' a5 R% t
+ d* U( T, d4 p
The World 3.x! p* V& ]& g8 {, |0 r5 a9 S5 K
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
! l& O- Z& Q6 p* h8 @6 w4 y
2 Z" m+ I0 \3 H+ m搜狗浏览器 1.x
' ~; {, P5 W4 Q' |  P% }2 VUser-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)
: _' i! U+ L2 J7 i9 g$ I( h/ |4 e/ b
1 Y1 I8 l) j5 S! n( }* n0 f360SE; A" }* U1 `6 e0 o
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
* j/ R  J7 v$ S4 F5 p- r% v# R* b% O& y- N& D7 v  z
Avant
( }+ w0 C/ s6 m$ y' XUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)6 `2 }& d' Q2 d6 \2 i! O# J

$ X/ H$ M6 R/ MGreen Browser1 W: t0 u* X4 _( o8 I
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone& f: P  ]4 J7 K' f+ T  o4 y$ W
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" }4 e$ X  P# X) ^- y3 d( r

  m* W# `( z5 |4 z" V' h8 z7 _2 p# jsafari iOS 4.33 – iPod Touch- n3 l+ E- N" P) Y" J; T& P
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  t5 |- n' T. Y' |+ D9 x" W

3 G4 _. j. r. h) q4 L3 Usafari iOS 4.33 – iPad8 u8 k( o( y. O, U* K
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
) t' ?' @1 u5 U1 h% H, p9 ^" e1 }8 J7 A+ [
Android N1
# Q" {: ~& b4 W! ?# |8 m: A5 o. 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.1
- }5 t$ q- ^, c& j! k) Z% \' b: }0 a( u0 M( L
Android QQ For android
% s% _3 L, [8 @" z/ RUser-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+ q8 i7 z  y7 a  I" @2 v

  D& a; K3 B# o# B: ]' f$ B. I9 nAndroid Opera Mobile8 Q- I& A" b, Q) b! J' R( A
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.101 x% I7 |& S  D

. z- w7 N7 O# {) jAndroid Pad Moto Xoom2 k( x% _( b# _1 [
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
& j9 H4 f3 v* X( t, ~9 T& {) Q+ H4 N# a5 w' i; x  C
BlackBerry
0 W, i: m2 H- R" oUser-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- K) f' l2 Z* a$ n1 Q
% E. S2 D: d, p+ l- T, [WebOS HP Touchpad
" A! N( r, S! B: K0 rUser-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
8 @# y. Y6 u2 W% s" l5 J# Q: j' T3 x+ }4 v
Nokia N978 c5 \, @7 a4 B' l! C. n
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
$ J6 ?7 F  O# K  Q4 K' h1 P! W0 l/ Q% W5 e; J
Windows Phone Mango
) l' z. W  C3 ~9 c/ lUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
6 O+ y7 w+ [* n3 C! @8 W
- [" d4 y- ~+ I* sUC标准. B0 X% s% m4 b8 J1 Y
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999% F$ ?9 w: m7 h  i! e7 n# a

$ u8 \! @1 Z( w+ u- t5 [+ z, lUCOpenwave
6 j# E3 W8 W% F$ ^9 vUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
5 l& G  }- C/ {
# k# J1 p- e  ~$ E1 bUC Opera7 [7 C  W5 D3 A5 l- K
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
互联网安全