$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.         ?>
复制代码
# @$ C$ y9 R7 i; l+ p4 ~$ n1 j

' {/ m1 c/ H+ u; O! Q

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

/ L. @' `  O  S

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

" L! a$ A1 K$ \# w7 Q& C

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


7 M1 ?! s! X7 |8 q& c4 Y7 F) T+ j/ E  q' t

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
6 a) G2 q1 N# r1 b5 B+ H( eUser-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/ [0 q3 N) s; i- Y0 a( x

5 K, l5 g9 z- ~& q7 U0 [7 J$ ssafari 5.1 – Windows2 W$ V  @3 Z5 p& i& g9 `0 @
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
- n5 y/ k# Z/ d# S! @: J- r7 ^8 q: E, M9 e
IE 9.0
- f# u% t7 _$ m& t# i) MUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
5 l) Z6 _% p, x+ X5 Q# D4 C8 k  X& ?$ U+ W/ m+ O) X
IE 8.0
5 B: w4 |6 T9 |/ q2 y# M0 ?5 T. ~9 fUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)5 R$ x; S% G! e$ L
3 J3 N* p1 J! T- y4 d
IE 7.0/ B) S: M8 R; A
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)6 N7 y. x, O( z8 X/ j. d
. O- @4 q7 c+ R8 S, w# F, |3 J( t
IE 6.0. Y! f9 b) ]1 S. y3 B
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1); H% o+ ~5 m8 g+ x! b8 I
6 k+ E. c# ^5 A; b  D1 w% l
Firefox 4.0.1 – MAC: B6 G3 H% t% @8 [* o( @
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
* A4 I+ @6 ?. R- k. Y+ S! u3 U+ D  f* p: o
Firefox 4.0.1 – Windows
! q4 F0 M9 N! JUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1& d' X# K  {/ r# X# R8 M

8 i: O* A3 f9 I9 a1 Q7 i' D: z2 M+ z3 gOpera 11.11 – MAC" L7 n0 h5 Z1 l! y0 K/ a
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.110 C' P& |% j' k) `1 H3 J3 G
' Z8 ?; G# e! O' a
Opera 11.11 – Windows' F# I# ~" H0 s) r( _
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11; B- k! `  [. K+ B  h/ V* g

( ~& g; n0 o6 W& rChrome 17.0 – MAC! W0 I) F3 y. k9 P
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
; |. d5 j6 J  m2 e- _% ~7 VUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
, ~* w: ^3 ~5 I9 O8 v, d# l2 S0 P6 k1 m
TT
+ o1 F8 V2 T3 X1 w+ o. p4 KUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
: c: x8 u" b; Q) W6 x; ~' U6 W; k
! a, J0 G2 G0 N& O7 ?The World 2.x
! U# ]3 N8 N6 K/ `3 [4 ~User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
/ b9 z: U# O6 S6 i. O* Q; N* k# H/ `
/ D" }; h) O- GThe World 3.x
% `) M5 _  |0 {! d+ H" a: Q6 ]) dUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)9 f& o$ U* N9 \
" ^( V9 k0 j; p
搜狗浏览器 1.x
2 |" [& }& V9 h. u* J6 tUser-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)0 T9 h8 U( B' u6 u0 B% B! R, R

. _" A5 O- q9 G; [360SE
( W9 h3 q! t0 d; [' qUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)$ h  ^. x% Q- s% ^; ?
# v$ p4 j  \$ A) e: ^
Avant
* ]! V1 ^5 f5 l; w' RUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)' O, \& h, J9 \% Y7 `& U" s

6 G- o4 m. h$ e4 z8 YGreen Browser& {5 @3 Q. d' J3 i. _
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
0 _$ S5 N4 s( tUser-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.54 j/ g  B4 E" p! w/ W# V
: U. c4 H, C8 R  M9 X
safari iOS 4.33 – iPod Touch2 }; i7 H$ Z- r
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.50 J" [9 P% ^  t2 D) H1 u5 I- U: `
$ I2 f" ^0 k, u' J, A3 [6 A, w
safari iOS 4.33 – iPad$ \( @" _; [$ {: z
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% i  D! B$ S) b% v( S

4 H& p* j4 W$ ]5 r9 M% TAndroid N1! m; o! A9 D1 m- `
User-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, v* o: f8 _8 q) n; H5 ?7 Z+ ?! C
& C* |; G  P. Y  F' W  Q
Android QQ For android- Z; `  N; W# Z8 o  y, O
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
" L+ s7 [$ E4 [# K1 J5 F' j0 V% I1 @& y8 y" Y1 e0 }# Y
Android Opera Mobile# a( z+ B; U3 j" m
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10( F* {% v5 ?. ?' m! h3 {& a
! }% x2 U. Q0 P$ ]( S
Android Pad Moto Xoom
) ^9 q2 {6 L- T: a, x3 zUser-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
: ~8 E+ }$ w6 f9 o! f' l
( u" R; f& u: F% A) WBlackBerry) P9 V4 x( U4 o! p6 }: a1 f
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+" z/ [/ S/ l$ K1 P
+ z9 w8 ^' y$ a2 h
WebOS HP Touchpad) [  [& `' ~  r0 d# g% ^7 H+ r
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( L- i& k4 B3 T; ]3 L5 E
+ J* ]* \3 W3 J! ONokia N97
, I" b2 t1 a. a5 C5 bUser-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
6 _" |$ `5 M! z0 S5 o# h
, g, Y3 N- X7 L9 U' Y7 [Windows Phone Mango$ z/ S* r  W$ Y2 U3 R
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)0 A' a& f3 g/ r; t/ z

9 x0 a4 u% W7 m6 T+ N  @+ K5 |9 ^UC标准
  _& g3 e3 ?, b1 z8 Z! VUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
8 |) N% |' M: \8 v  M7 @( V; u; I0 a; k4 I; E  n- u
UCOpenwave+ K' w" g6 U# X" n- j
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
6 i3 k+ w+ R- j/ ?3 [" |1 I% Z/ a& n
9 R; V. D& c3 }* }& W3 aUC Opera
- T/ n' {. L0 P0 D  Z  u4 GUser-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
互联网安全