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

: o4 q$ B/ e/ Z' Y- X


* b) p* T4 |1 B/ G% f4 ^

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

+ F+ V$ n/ c2 N0 Z: \% H

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.         }
复制代码
. `1 F) m5 l+ g4 L% g" r6 p: I

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


' R- z+ @1 a. H/ ?: T9 w, I
8 T; `, @9 ~8 |) O

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC$ x& J* ^  _: |& o# ~+ j2 x9 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
" v" W/ O9 l9 N1 h8 b7 k
/ D4 d- j  I( T" l  k" |safari 5.1 – Windows4 c' T5 o' d1 Q) Y
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.504 F9 S% u! ^# o, f* e3 i! {$ v

. a3 B3 {3 W9 |9 d4 x1 jIE 9.09 \- e3 ~$ L7 y( H
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
6 N. v1 i3 `( k1 N8 a/ ^0 C5 ?# o' _' _& X) [+ Y: x3 E
IE 8.0
" w) |5 t  ]5 I$ L. Q+ g0 {  bUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)3 |/ t3 ~* ?8 X9 S: `
+ Q; r# B" z& F) @! G4 e" k. g5 \  n
IE 7.0  Y2 T% R8 q- b& S: ]8 O
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
+ G8 ^/ q% Z; J5 c4 N, M+ x7 @$ q0 {* A9 g& l
IE 6.0
3 I. }4 r$ ?5 X% DUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)9 v) C* C( ^$ k# @( I

( M. X4 m! U9 @  mFirefox 4.0.1 – MAC& M( Z/ q7 o9 q, u" p
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.13 o1 z. j# l9 W. j; v2 R( V

( W+ @2 w3 A! T, ^# k) PFirefox 4.0.1 – Windows
. [3 |" i. b# k0 n) K0 g+ t' U# K' eUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.12 N. J4 Y3 N. v* G
' b* I) C* w4 v0 |$ {
Opera 11.11 – MAC# N) I5 Q! C/ D1 M* y8 V
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
1 Z# Z- Z% q8 E: S4 U7 |  f2 }
+ a2 z$ E2 c7 h2 mOpera 11.11 – Windows& n1 F7 W& P5 A8 v+ j2 L
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
: q1 B8 ~: ~: Y0 q8 \* G  H0 e
/ U+ t2 W2 E5 @7 q( o  A& tChrome 17.0 – MAC, f# `7 r8 i0 a  P0 d3 Q
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
$ ]* U  ?5 r5 f4 k2 o6 j8 y% n0 `3 H, PUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)3 Q' _2 \8 ?- d% z" ^
( \% |  {& ^5 p, _( |
TT
2 K; V! f& k$ j( X. _$ v1 ?6 W6 vUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
9 H3 j! R1 }: I4 _
: n6 Z3 g  ^- c5 O7 x1 L* kThe World 2.x
+ x/ Y2 r' j' p5 G. ^User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)- M' @$ g; D, |. ~2 m$ _: a
$ ~" V1 j$ m5 R+ N# W9 n
The World 3.x' U: c  \; `0 l6 p- n
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)8 f, l( q% f/ `, C4 D! ]" B
0 ~" P2 j" }( z7 T  h
搜狗浏览器 1.x. O9 b& C5 S# d2 @9 A0 K/ J* x& B1 _3 Y
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)# e7 z) _2 b$ U9 b
$ R6 {& C( @6 z
360SE
8 q; E. X5 ]$ h4 L( b$ @8 Z  sUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)  n2 p8 c7 Q: V3 W; {& E

+ u+ R$ L, b; `  C2 mAvant
2 R9 B$ U- O, n7 t* t- j$ f! lUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
' [( j- \. H: G2 `8 H5 g
% V" ]( p0 p' U7 o7 rGreen Browser; j9 @+ n5 D  X+ k+ W" v
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone3 `1 h2 U0 y: G( v# B/ H. l; e
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.53 O6 j7 W' P2 y6 R, Y; f3 w, U& @

/ Q. Z" J4 M" Z% ]# l2 Psafari iOS 4.33 – iPod Touch) d7 h% ^0 @7 i1 J9 c/ g- i
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( ?+ E5 q3 t: P& q( \9 d7 p

) c* K* F8 ~. k0 R+ Z( M. bsafari iOS 4.33 – iPad
0 ^& d; G/ T) [" M0 I  h  SUser-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
& `" r2 H2 Y0 H2 J  x. _
" J# b& s. G! U" @0 z! Y* L! n' H! FAndroid N1
5 l) W! ~& d2 u# x% Z0 i0 ^7 S2 bUser-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 o- P' W8 S5 c% p' ]1 u
1 g  S( b5 j$ U  N5 m7 tAndroid QQ For android0 m: O6 N* @1 E* W" |7 g
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& |9 W+ @$ n0 B& L5 O" b" h  M
/ t$ R! {% n% s0 ]- Q
Android Opera Mobile
3 C. P# v5 h) A( G7 dUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.105 t0 I8 M! V4 p3 m4 |8 J, j: s

8 W1 j) A/ Y" J, c4 \  I& J  ?Android Pad Moto Xoom) z+ V: G1 V# x' V& W: r* a
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
1 y( @, A' O7 V6 p  L9 W: {$ z; c
$ c3 Q# o. H/ e4 |! C6 z. eBlackBerry
6 n' I# N/ @: p3 LUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+' u7 c8 R- f' _: S

: Q3 ^# D/ A# }WebOS HP Touchpad
1 b1 T3 b6 b9 N5 O( T. {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) I0 Q. a" [- @5 y" m# H( B

' Y. V. ~+ ]1 o$ N; I4 UNokia N97
" E3 c' F- G! gUser-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
; A$ K4 f$ M0 t/ `! P
0 Z; z: C) d( mWindows Phone Mango
6 y3 F; n$ @0 S+ B* u; B  L- ]User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)4 ^4 r9 `; H3 ]) T- G# l

$ v0 `  f3 l6 D8 ]& g" H6 r. T( \& OUC标准; Y2 ~7 P% [4 [% U9 i; X
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999. f5 e! H9 n* h( b( X' \

/ z& H4 ?7 X! }8 [! u% G1 S  LUCOpenwave0 e" Y- n8 {3 k: J
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
2 A2 w. V9 N3 e- @
9 s. J6 r' ~/ b! Q$ kUC Opera5 l# O9 M6 E$ x; a
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
互联网安全