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

! P: `. L0 p# t3 O/ L* u9 F


: ^$ L4 x" @4 w" L2 C2 N

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

6 K7 l/ V9 j' f

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.         }
复制代码
" V& n' y/ X8 P, i) |+ v

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

/ q* q# ]" K% w# B
1 h$ ]% K$ Q* n9 d6 H

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
  c, l# g( g# U( {5 h6 X7 T* PUser-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
9 z/ H4 a0 h: O4 d5 }3 E
7 C6 t9 E. Q. g/ ^safari 5.1 – Windows" q# [, r+ f" ^. E3 ?& E
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
' c+ I$ U5 Z, V- i/ h% q' R( \# {
% ]# i7 s( S3 X4 T# _IE 9.0' W, |  b. A/ A, }" d" a
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;; L. S. M* m  h# w$ ?9 E& f
+ o) W3 v8 g7 \
IE 8.05 a: i- j, p8 E0 Z1 Z8 x) N
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)! s( w5 \2 `2 x
5 j- H* x+ J  Y: ~
IE 7.01 f0 p* w: x( v# J/ {. c, @6 w3 M
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
' u, w# d! \1 \) u7 u) N  y7 ^
5 P* y; i' f  F& U" a' |- cIE 6.0
% H8 e4 S! w4 w6 mUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)% c: Z7 [7 [' p8 H* _
  S2 ?4 Y1 X9 |* c: r
Firefox 4.0.1 – MAC' @5 S4 K- J  ?; p4 }  r; t" J" \+ n
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
  \& Z( e$ o" N: Q4 \! y7 w* c! Z$ e0 W7 l5 u
Firefox 4.0.1 – Windows: z, W& x2 m  @( P6 A5 P
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
9 h" e0 n; }5 I# E! U7 W" n
+ b  @& m2 @, `Opera 11.11 – MAC
/ }, R+ H* V& i( m% v( j0 {) @User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11. H) m+ \4 Z7 x6 w3 T
9 [9 p3 ?% K8 B$ ]9 W, D9 B
Opera 11.11 – Windows
6 `# _/ x( c8 `+ t& c- \- AUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
2 c2 Q) A+ n/ r$ V, o7 L& n' H' x$ I+ D  p8 V3 E" p
Chrome 17.0 – MAC
* z* h9 S. m/ sUser-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# U6 m1 h$ B: Q4 R0 u- n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)2 ^( }8 C* ^. k+ i- T: Z/ K

5 z9 X$ N, s# Q, |5 ?0 P  aTT, g, [9 }, x1 p9 ]4 v3 T
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
- Q. V8 E9 a2 ]. Z# m4 D0 C( U% Y9 S/ D$ ^8 `' `7 _' x
The World 2.x: L; S; B' B; k4 l
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
4 X  P" x* `2 u' f
* X- w2 G) x; \6 R! NThe World 3.x
3 M& [$ |/ C5 O. \) N( V9 GUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
. x0 k0 I, Y. z, L
# F3 F: l* B( {* ]" h- u搜狗浏览器 1.x% Y$ E" @& [& `
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)
1 L( t& t, }- s" z! t) F; C3 q( S4 N, S5 D7 K* K
360SE
% k( e* U2 B- BUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE), z1 ^6 @2 R/ l7 f1 U. [9 e

& k0 W9 ]$ G( F3 \Avant
. G. m* N, F, gUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)9 a8 O) F! e4 [3 q9 T

, R$ m& G6 m2 ]. n7 L# }- VGreen Browser' l+ V' J: m. c/ t
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
! R5 I/ C1 a2 _* V: eUser-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) W  q. ^6 A, A$ T* \8 p

% r- b) x; B3 }0 P. ~safari iOS 4.33 – iPod Touch
5 u4 }4 g2 k! F7 \/ N2 NUser-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
. }6 v3 X% }7 D+ o2 S" k8 A* S
$ y$ \! }( U* c7 Z; Zsafari iOS 4.33 – iPad7 @# O2 v3 Y, h! w9 h) j
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
1 k$ o' p5 c* V- I/ i; _- |7 e& G& |! ~" P$ H9 Z8 U) ~1 b
Android N1
5 L. u5 v' U& O, S. S. [8 y" WUser-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
* I& r% D% R6 e6 g3 @' X; M9 H- _
Android QQ For android. u6 `; _# g6 ^* {% p+ F
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
. n% J  n9 b0 x9 |7 Y9 P
; J! Y9 y, V6 I( D# @+ nAndroid Opera Mobile! q2 \) t) G# h
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 c4 p* K8 P$ o
+ y2 }" M, Q/ D* a" ]+ a0 m( NAndroid Pad Moto Xoom
3 n% e! q& N8 r/ KUser-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
+ G) _% m! ~2 R0 l/ d- j6 {+ d2 Y) O& j2 x- i9 E8 L- s( Q
BlackBerry
9 ^- y' t5 m( I% sUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
  C( P& p! O9 D- A/ y9 f
+ x$ x! z& U4 U9 e% H( FWebOS HP Touchpad
3 q1 \6 B0 z2 Q8 F& i& TUser-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. k2 _: H& Y' h( @  f
# g7 i" A; S; ^2 W
Nokia N97
0 Z' y" W( M' D/ {# l6 L7 HUser-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.181247 i. M7 F, v' W  }- E
( ^: ^1 _. o% _  Z1 d4 B) h
Windows Phone Mango
+ f4 R& N6 _; g% z6 _7 r6 [5 wUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
% }/ J6 }9 b3 v: r2 [4 `+ B1 p' C' i  g1 v6 X  A$ X% ~
UC标准/ A8 D: ?* C8 {6 G0 G$ \- |
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
; W- B0 \8 X+ _- A
" I0 E# N, t( s, M/ K, Q' cUCOpenwave; p8 X# \& O) U# y: P, c8 m7 `
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
. w) O% a1 m& z. P1 l6 u  D# }7 M% I
UC Opera+ n5 y* `, b' [6 h6 n( B
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
互联网安全