$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.         ?>
复制代码
! E, d' n; m5 b4 Q2 Y+ Z2 \


: ?) P: `/ |7 p! o* V) J' Y

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

0 i) u2 Z. W. Y: E8 ~* U7 ~6 }

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.         }
复制代码
% i6 H& x8 A4 A! g+ K) A

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

  L( d. w( K- {$ K+ Y
9 `( `" a  l* c. w( c

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC- r9 h/ A+ V( h: W; V
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
- G" e6 F; W# y/ S6 C+ S5 s; l2 o6 d* @8 c$ O# r: A1 L7 B
safari 5.1 – Windows- ?1 L: q  f! x) L2 y2 G) f$ t
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.506 K( A. I7 L% l: \

7 X; U+ m# m2 d8 H+ H( s3 D& ?IE 9.09 F) p4 a) `5 C$ K( i7 `
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
3 J7 q- D) h/ I9 M: S/ T4 C3 @
0 r5 n3 E! X$ J, pIE 8.09 G; n; H. w8 S. b# X
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)$ q, a1 \1 i5 I( e& @* j" U2 H; T9 z

. t8 P+ m. U' x+ }# [; W0 pIE 7.01 u! \- G0 P4 Y5 ^; M0 D
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
+ s! ~  ~" z% V+ m7 M* S9 p  Y" ^" \
IE 6.04 e, _# I: E: w6 w4 ]6 `; y" o
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
$ _5 p7 F' G, ?  z6 T5 J8 Z  s$ i, K- Q  K, ^0 A6 A) U) V% J
Firefox 4.0.1 – MAC8 u3 [( E3 ]2 u3 Z
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1! u- E* u% ~$ ?2 H* j* `1 _9 A% s
* G1 u# e2 ~% \# N' r6 |
Firefox 4.0.1 – Windows6 S2 ~5 g  x# k& a+ s; g; x8 \
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1$ @, B  B! w0 d2 R; g1 N4 g

4 e, @) b, `/ W7 U& F6 C7 @2 |Opera 11.11 – MAC6 z5 z2 C. }4 H$ p3 J7 z4 I: ~
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11& c& N, |5 l( D/ T4 S

: e# c0 t* C. \; f  w. k) WOpera 11.11 – Windows8 L0 \" A7 j- O" Y
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.110 `5 T- Y8 }+ c

1 ^1 M# ^4 c" V! ?' W: x1 LChrome 17.0 – MAC* G& E# W+ [4 b2 |
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
. E0 U; n0 ~9 pUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
) t  e" T7 W' `$ ?! B1 ~# J8 d7 E. M/ }9 l5 H* T. S
TT
, C8 D& Q2 B5 D  v" ?/ v& mUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)/ I+ F0 H" Y6 P" B  W% Q/ `

- s* R; h8 p( \6 E7 vThe World 2.x
0 C3 y# I/ q3 ~, P3 A" Z) `/ BUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)2 y' a6 A1 y7 Z/ i" g$ C0 f, ^

. P0 C+ a! X1 h6 M9 e- b1 EThe World 3.x
0 @' U( d9 _) o/ h- _- TUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)4 L) W  G, b9 `3 L" B2 q
9 A/ o$ z! e, |, [
搜狗浏览器 1.x; {4 l0 f/ x. w
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): J! O1 X8 y( C0 t9 f: D
# b- w5 f' l# U1 m) b
360SE$ W2 H9 g) g! e
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)+ r! m. G0 A. a" R; U) P
$ t3 L1 q: t- Q0 G9 V. b
Avant
& I; m9 M* [, S8 ?( Q2 C1 n- YUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)/ Q5 }, ]; O" s/ @# {4 M7 r  e$ z
8 l! w7 P; y7 T3 \' O5 M% ^
Green Browser
$ c9 p* Y. D- ~7 J5 A( j) z  U- VUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone4 ]9 F: t& U) w9 J, G" |$ t
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' }8 M2 n  s2 j) F9 A( O% g" j; n
+ N' \/ i5 f% {! W
safari iOS 4.33 – iPod Touch1 L% \# k0 g+ Z! P( o! l9 |
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
- D7 W5 f  p; v) ]5 p' y% m4 a7 d& n  o! T& g  Z) U6 }" H" }' q
safari iOS 4.33 – iPad
3 s/ g0 b; t) f- l. y5 ^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# e* d8 y) \* t
1 r9 V+ d0 d1 A3 B
Android N1
& Y( a* _" r0 N( f7 Q" }5 hUser-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
4 X- D. S9 r  L2 R) O
7 P7 S1 Y$ q1 ~4 S; tAndroid QQ For android
0 q6 T& x& \. l. _( X4 s5 y; u% |# MUser-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  B4 L1 c" Q& b! b1 x

& U6 A/ R) v. b6 R8 B+ b) q; [Android Opera Mobile
2 |$ B. z1 w7 j, a0 W. iUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10- n- @+ B; ~) n1 Y+ j/ p
$ e% f4 I- W$ q% z1 |9 P. f
Android Pad Moto Xoom3 J6 h+ d) K' F: U; ~
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
7 D2 N3 O* q" e& i7 D% _7 L4 X
+ d, F9 p" K" w; i) C' SBlackBerry
/ a  t6 J- L5 _# W# YUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+2 N( J% Z$ M3 x4 [' |
8 l2 q0 D0 B3 \7 _* V* x: c7 i
WebOS HP Touchpad' `1 l$ z& V* P  K% S) z9 w; u
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# d  c4 M$ O: C2 |" u

# {, L9 ]* V* b: R6 cNokia N97
7 D' P! X/ ?5 a! c2 U; D7 i8 YUser-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! v. m3 T" b) ]: z3 F% b  D

! n3 }- I0 @6 r, kWindows Phone Mango
/ R  ^# c2 r1 B' F/ HUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
2 E3 O5 R1 T$ N: _- U2 s
- y$ l. |4 ^- T+ T' kUC标准
! u8 E# k! c; O( R" }% S5 T$ ZUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999$ I2 z5 `2 U1 u& N  r$ e- J

; C' _+ j9 N# G- I% U3 MUCOpenwave
0 X& n& t9 C+ l1 d% h* h  yUser-Agent: Openwave/ UCWEB7.0.2.37/28/9991 h/ r( S! y5 C0 a& O' Z7 `

- @  t, Z7 R' F/ K- W/ S" {UC Opera- s8 d% ]5 T0 S& k: C
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
互联网安全