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

- y- H6 E( C* i6 |# H0 w7 m

( q2 X5 v  S( b5 V8 E$ Q1 S

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

3 B& \% u7 r" P3 I/ c, n) X3 Z4 h, N5 U

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

3 b+ W, O3 J4 x$ z) i3 [

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


% U$ {% P$ h) J1 }8 ~! K: [5 r( {+ H7 W. r. B( S

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
3 V& G8 {# {( `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
3 z, M% z" o, R+ m. b* I& k1 F6 D3 p% i. G9 ~2 t' M" ~  Z- k: ~
safari 5.1 – Windows: |9 H* x$ ?5 `! j
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.508 u2 L* Q0 A& o, @

/ Y+ O6 O( F7 q: v, RIE 9.0& w! c# K! i! k" n" v
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
4 m2 g0 g5 u+ n( G7 j
! v5 U! v. T- g' P0 AIE 8.0) v  G* d2 t7 E+ o' [
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)6 H/ p$ J6 D& b: q0 M" Z7 I7 c" r

" s* f3 Y  p/ nIE 7.0
( {0 t- {* k+ X# a  N1 Z$ wUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
9 D& {9 G/ S- _4 W
8 l% [& Y& _1 v! YIE 6.0
% D) t* B5 U0 A0 w) DUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)7 y- E" Y. e7 n
/ E6 B+ M) U- P$ e) S4 r
Firefox 4.0.1 – MAC
1 G+ Y: W3 x2 Q/ l$ @- w$ R0 TUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
- L, J) V9 h6 ^9 J0 _
& L9 t, A$ Z5 n6 m) MFirefox 4.0.1 – Windows: l9 [% W2 e" {. M. I: A" e* l% [1 h
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.11 `* T/ X3 u3 k5 x7 x" c; y

) t0 H, `% E8 [  x/ G& fOpera 11.11 – MAC' g& t/ u; [5 c4 D4 p7 U& D
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
; k  A0 N- m: Z" T$ J# P7 L8 P/ m( L4 ]# y
Opera 11.11 – Windows; k& n& m, A& b; x
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.115 k- U& O2 I, q" X! S9 H

' _% e" X( Q* F4 n. H+ E, XChrome 17.0 – MAC6 I7 b" i- {  W4 m9 [  x
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+ d4 C9 Y' C( J$ |5 Q
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
; r/ A8 F  s3 O- S" C4 t! b6 p/ x0 o$ |6 Z) S2 B
TT- H7 I) P: p+ S
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0). [) B1 r4 ~' v( \2 D
7 v. n6 a1 @* W1 }; J
The World 2.x
2 N$ j6 i: k- x1 t! g% G( z* f; fUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
* }+ {; n/ Z) v5 v! K) @$ K. U" E9 B# _2 E2 z
The World 3.x# C" m8 r, E8 A+ h2 L: j7 o
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
  u3 {0 |6 ?% Z
) k1 k; v1 Q4 v% K搜狗浏览器 1.x
( s$ q/ }- A/ U* k' N) 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)
, Z, R7 Y# u' ~* }3 n
( }5 H. d1 H2 z; H  @- Z360SE
( D: b2 M( W0 B8 p, Q0 L# AUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)* }+ o, f( k( }# W
6 Z% \* X3 R& M
Avant- ?8 y9 L3 E6 C0 N( ?# c/ H: H/ P
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
  M5 n1 g; r% @2 g: u* N
1 y% F, k/ _9 h( ]- k6 }' qGreen Browser
& k) |8 j/ X: b6 P: aUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
6 }0 ]' Y- W6 G. ]* S% h/ O0 \; cUser-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
( N  V' B2 C% r6 o) R
# u/ I/ Q$ }9 @0 Gsafari iOS 4.33 – iPod Touch
; B; V+ m0 n8 f/ r: RUser-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; x5 t% d% n; ]3 w
1 u: i$ S4 L6 B3 n0 p- m
safari iOS 4.33 – iPad! {+ {8 E- _7 Q% C$ ~. `
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, D  K6 \! E8 e8 X) e2 m5 U4 X. l& R
7 L) {  Y* z" B& r6 k; g" P8 q
Android N1
4 V) t1 O- P( K2 Q: W1 lUser-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
6 M" h7 s( \( N% \7 i  t: D$ d1 `9 W9 ^4 Q% A) f" z7 t
Android QQ For android
- U3 v! R* B# S) j/ PUser-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.16 M& D" y/ P8 v/ u4 v( F$ O7 a' N9 p

) |/ ~1 J0 U) ]5 f4 f% FAndroid Opera Mobile! _5 |, J) A% S/ J1 @- B
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
: {4 b9 P6 t' d6 X! y6 |% j6 j% B- K# S% }6 r
Android Pad Moto Xoom
- Y7 q% a( {: uUser-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- t9 \( F  Z. a( T+ ]

# f, m+ z3 v& Q4 B( aBlackBerry! y1 ]) Q, e& E/ _3 Y! X8 O
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+: u* }( S0 `7 _2 i5 G; u6 g

/ _7 A( V5 Q: x" Q+ BWebOS HP Touchpad) r: a% q: t0 E& J# F
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
! V. C- u% J# ^: U2 R) c( |, ^' H- ?( U) X. q) y1 C
Nokia N97- n/ X3 C0 B7 B
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. u- i/ i- g$ U7 m3 Q, k
( z5 o1 }& C' l5 q( @+ o
Windows Phone Mango8 ?' Y6 I( ^0 o- p
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
( N( A/ \6 D8 J3 g/ X- H2 b1 s" m% T' l9 t% t
UC标准
9 |( ]. h: ~" G( M7 [User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999# |# p/ N1 |8 e- \( c/ T/ {% Z

9 i( U- f" A* QUCOpenwave& X2 [% Q/ I* g% z9 S1 }! a2 L' x
User-Agent: Openwave/ UCWEB7.0.2.37/28/9998 O/ ~, s- y  [& G, e/ g* w7 `6 c
* R1 L3 u0 x8 t& X
UC Opera
" S- p+ ^* m% w- O; R# }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
互联网安全