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

+ r# d+ p* K7 h7 I0 n2 l8 z; x

0 [  G- h! v7 ]' B, ?' ^

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.         %>
复制代码
, t' M) @8 j6 H7 E$ o

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.         }
复制代码
9 L4 M* b  ^5 w# o9 R: z5 r; y0 q- j

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


4 }* O# @. @$ R5 a" B9 A
( y' |* \7 l# N7 v3 ~( R( Z

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC  W; F3 m: `. 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.50
5 M: R0 O* G: Q9 ]0 R* [
+ t) f7 a% |- r/ Fsafari 5.1 – Windows
( e- b$ a4 K7 ^3 OUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
& V& t9 k8 d! m$ b* U" K8 D. ^
IE 9.0! p' X/ H1 o- \9 i: y' l. l
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
% ~3 r/ R& ]$ a) Z& O
" J2 b( m: ?# T# rIE 8.05 A9 j7 a, X1 T6 A
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)2 ]2 \$ _! b( W/ O, N. O

" X$ o6 S$ [: @! cIE 7.0- w6 G* F3 u# b6 a7 G1 U
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
2 u! \5 x, B! m* _* [6 W4 y# u+ H$ k) Z( \1 Q" g
IE 6.0
, L5 A* [" b: Q2 s; w7 GUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
. w) C9 f: o2 g1 h8 `: O2 Y& I) ]* P2 ]. S( ^, e5 d
Firefox 4.0.1 – MAC
! i$ c) s. q4 I1 {! SUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1& M# }! }4 _$ d8 I& s

; O+ a- s. b# qFirefox 4.0.1 – Windows
' q" C( G5 l6 d+ m% y* P! X* e- c# VUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.10 D+ o8 r* o3 H7 V9 B
  Q0 H% Z! U# {9 X
Opera 11.11 – MAC
) o* m0 i; {2 m( I/ OUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11# n$ e, a. {0 B/ ]% R6 V( `

5 n- W0 {9 C, _$ F: \: a# F$ COpera 11.11 – Windows
5 ]' t( T- m9 ^3 {User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
) X. l3 U' E% G: v. l5 I, B+ G' R$ D* P2 Q3 w0 A0 Q
Chrome 17.0 – MAC- t5 ]1 M8 H9 x: Z+ l* G
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  K6 P4 r0 h2 {. P
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
' Q+ B; K  A+ ]% r+ W. M5 u6 g( {! t" J8 |
TT
% r: ]5 C/ G: f0 V* `! L1 y) f5 o5 XUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)& {! A' }* i" y% ]8 Z
8 _' O' C6 e1 f; N
The World 2.x
" d# P  o& g) T0 A$ t3 I  ]+ zUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
# V$ Z1 C' J! p5 Q+ e( E& w, l4 X$ [5 |0 b- J( j
The World 3.x
$ e- R. x! \" H  @3 ]* R% d" bUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
+ P+ x& b4 [* i$ D. k4 E$ V
9 B. v8 K6 @7 D! K搜狗浏览器 1.x' B) _  |0 |/ `; S6 e. H
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)3 D" E) S/ J+ O* C6 \( W2 L
+ h* y& J& \/ S# I
360SE
, G' P2 H) _$ U7 g  K4 ]! b0 JUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
! F. v* h- r: P; T2 K4 g2 B( i5 s
Avant- B+ V' j) ~" ]# m
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
. B$ `- u: j$ R! W; ]2 l0 T" M6 R, l3 o
Green Browser% o2 @2 n/ Y  e( v
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone: ?' O9 m* u* \" r
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.57 F, e2 e) @4 {6 M/ I# t; X! Y  i

% d# v; s0 m- n* ]safari iOS 4.33 – iPod Touch7 Y) e+ G. ~8 A9 H! J2 ^. @% t5 D
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
- L. y. Z; w1 U+ ?' R# O9 Y  R* l+ C+ o" g
safari iOS 4.33 – iPad$ `; O# l8 }6 {! n" U# r
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& m& Z6 E% F' q# J
. R" v$ H) ?# }$ p0 A2 ?
Android N1
1 N+ M' x) C( r& RUser-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, }/ ?8 _* L+ e9 V8 f% d$ z

! }: d0 V; `- a; \3 ?; H: mAndroid QQ For android
3 f- W0 ^4 {1 k3 c6 [% L" |5 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.1  g0 y6 N/ ]2 c3 M
$ F1 E& n0 a8 }4 _, h1 X4 f
Android Opera Mobile: x1 O* @% {# J) z; G
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10* `) n( I) d) Q; J. A  P
, v( O% J6 P6 m2 v* d, \- K! @
Android Pad Moto Xoom
0 f' T/ E9 E% o, X# E+ o8 t5 ?/ [- ~+ gUser-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
3 o9 P, h9 m$ k/ m' B, ]! b; _3 T
BlackBerry
0 D+ `& n1 D; k! _) N& U9 FUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
( r  u/ [: n! \. w: L! @$ r! [: _) v: Z, Y2 j+ t
WebOS HP Touchpad
8 M2 y" M0 x3 h% gUser-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( G5 l/ i4 i7 a  I+ a( x  ^

: c6 t5 f7 s# CNokia N97. o, T4 v1 Y9 F& ]- e3 \" z4 R
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) y) O# a& c! J' H! T1 O
2 i* k# I2 [0 W+ F# B
Windows Phone Mango
' H  j/ R# V* G7 y7 D% FUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan). L0 x. H- F# V
" e7 {& [+ F: k4 k. U! m0 M
UC标准
' Z) i1 o7 M) uUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9993 `% `& d2 K$ X9 j9 \
" v) w0 W1 J6 T. L5 M
UCOpenwave
$ O5 h% q6 \0 v( A- m! AUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
. p! O  `! S  O: }  s' f: Z  S4 |4 e( W/ |4 v. \$ n; M
UC Opera
+ J5 T# Q# p0 g" UUser-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
互联网安全