$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$ e9 T4 T; l1 u) |


% h3 F# E4 ?( @

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 m( |, r# s  v9 r2 ?& J

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

0 `: A  H2 y3 a3 E! d

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

$ Y6 q: t( F; s! {# u
" m/ B: h# q9 T

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
) S/ m* m) p+ _, xUser-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.502 D5 ]& z! D% {; C4 T" ]' b
! r! {3 s% \, P. B9 C
safari 5.1 – Windows4 Q$ d% v; _' A  I! Y2 `) T8 r
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
9 Z2 K3 o9 C" e
2 P& h* m; R# o  D' d$ h6 kIE 9.0
3 d8 m3 o9 O2 R, K& S- c" I- F8 jUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;. P$ M  l4 ^+ G- T6 u

5 e- W% x3 j% kIE 8.0  T( ^8 B; J. n- f6 J0 d. O
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
6 }2 K3 X0 M) _. y( w
" N9 y/ E3 O% ?( R: o+ u3 ^IE 7.0
. \0 ^: c* V, P) u/ u2 L3 dUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)5 [) H! D6 _' U* ~
* z) ~1 Z6 B. k# T! j
IE 6.03 W  l' B% A& p! b1 k8 o! z
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
( f$ t; i+ F" z5 _5 g/ q: e0 ]7 d1 C7 X
Firefox 4.0.1 – MAC
, h; V% ]4 F6 W1 u7 vUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
2 m: M+ C) Z- W* V' d3 O; c+ A# h2 S; q/ F9 J; }
Firefox 4.0.1 – Windows! I1 N. \, k1 s& y
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1( i/ B* A+ z$ I+ M; G4 \7 l. d
0 F$ g% Q  p* R8 ]
Opera 11.11 – MAC5 e0 Q' o( }5 E
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.115 i; a0 F" u# }0 y% y* P2 S1 H

4 e7 h1 b* {" t+ p% dOpera 11.11 – Windows  c" U5 B! I; O+ D
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
4 n) l: ]- ~& r* s
8 h/ c. z8 Z' ^9 mChrome 17.0 – MAC
/ ^$ u' j& p" Q+ y6 Y" {4 dUser-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# L2 {* s, A" D: ~% D
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)! Z7 R+ z+ F" P+ p; \* R6 s

& P3 T1 q: H- p# O6 c+ WTT1 K) v. f' t$ n  [4 B
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)/ S2 A. d5 l4 w( m7 \; `
% d/ K) A) f0 Y# [9 S2 D* X  L" l
The World 2.x/ q/ q- j8 _6 A' J9 F
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
5 e6 N8 v& Y+ ~* d) R" K' s' t( A& x; I
The World 3.x) }! f5 q0 e: d2 E' _9 Q/ K
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)" Q' m: O; i! G! M, s3 U/ v. t# Q+ o
0 ?- M4 ~9 _- p$ ?- X) G3 G3 M
搜狗浏览器 1.x
2 b) K" y0 E+ wUser-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)" t' m" ~: R( w( u- a3 w& L
  C- i6 L, }0 Z' G! x+ A
360SE
7 [1 `$ n0 [0 U( n3 x1 g! KUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
: t3 E3 H6 y* d: |/ E& v) J; A( e! P
( i. k8 G2 i& \Avant' G* K2 w8 V7 G. ?2 [: u( W, ~6 `7 c
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)$ s! a' z( S3 ~1 ~! P0 s

3 W5 p' U4 V8 d# @2 yGreen Browser  S+ @4 J, h. M; e4 R
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
1 l7 b* S, ]& X9 O, j4 K: `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
0 x. V- h, z5 s# a
0 J! @- r3 b  h: X. Gsafari iOS 4.33 – iPod Touch9 |& V" X4 h* o1 f
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$ z. i9 P" A3 A( J3 A- F

4 o( Z$ u( }5 z& g, @" v# g4 _% ]safari iOS 4.33 – iPad) Q- @1 S/ l! D) 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/ f0 |0 [8 u. T5 G
( q+ y  ]8 @! B7 L* ^+ t7 a
Android N1
3 R' r& ?0 f- z+ ]+ a7 XUser-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 i; y* q8 U, s* }; Q
" f# `6 Z. R5 c: ?Android QQ For android
! o8 _% O( K5 I6 OUser-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.11 _# F  I9 t' d3 @. S
, K# @( |5 Q: V8 e1 ~
Android Opera Mobile
: \' j" t) v# ?User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
6 l+ c# P; H+ i# m9 S# i" e# P, g5 w, Z" V6 p- f3 D
Android Pad Moto Xoom
6 E* ]" X# G7 Z- e+ k" }/ h& ~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
  A- r! D$ U/ X: }2 B" Q, V/ ^) g, T- @5 w2 g
BlackBerry( P0 J3 q7 l7 ]
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+
$ K: V( |, T+ t, }5 r+ \" C4 M
- k1 L% n  {" Y/ B7 j8 ?' t; NWebOS HP Touchpad
  E* ]4 e4 B0 J0 FUser-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
6 F/ Q4 W- i( a0 z4 k' @5 p: o/ C. B3 a  H* `! L
Nokia N974 _8 I$ u% f3 E# Y( ?7 f3 Q1 T
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.181242 D/ Q8 r( t& F2 l' V/ j

$ E: W8 @" K5 }2 _Windows Phone Mango4 r/ T, s; Z1 e3 i' O: W/ z9 j
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
: k- [; I+ k! ~6 ]: n& R. n- @; F, F( M: @7 f9 ?0 k) D& ~9 N/ E
UC标准
3 L# G5 K1 b5 S* XUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
" c! n$ a, F# S6 S1 K
0 M$ T+ r2 Q, d" ]$ x4 R. AUCOpenwave  O) ^+ O5 R6 L- M' N! f& g
User-Agent: Openwave/ UCWEB7.0.2.37/28/999  f8 D4 Y+ }9 |  p$ @& @# W+ p

9 A7 V7 o3 T. CUC Opera3 n* j8 F" C9 x( B) q9 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
互联网安全