$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.         ?>
复制代码
4 Y* D# i7 {4 h2 H& w" M0 a

4 }1 {9 m3 z5 G

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.         %>
复制代码
. E, d4 W6 D+ S4 [; z. {

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.         }
复制代码
) W% E8 |: d+ N6 a& ]

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


" a& q, q' A# R
2 u- D* G) F. c* X4 F

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
2 l# R+ T$ S! \1 W6 `+ iUser-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.509 {  E( b) K( r: d. Z) M) @$ z6 [% A

, `- N9 l5 \) t/ J( L- hsafari 5.1 – Windows
5 A+ C9 A! A* W0 J9 Y) Z3 i% aUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
& Z: m; J8 o1 I' n" L8 h! \2 ~' Q( x5 u( g" E
IE 9.0
" K* L- d. R3 _" V7 F- fUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;! S/ S) J3 K/ }# ]! W+ X' x

1 Y# ?4 O# h' h* q# hIE 8.0
( x8 `1 O* C, @, o6 r6 ?User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
" \0 C/ o8 R' {9 @4 {) e+ a
/ F. W; z9 @1 |5 H7 e0 m9 B; z* KIE 7.04 R' d4 j: u  a
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)( \% B2 d; }3 J' t+ b2 t( V7 z

& g+ e3 |5 X# MIE 6.0  D4 p' K3 [) e6 w
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
1 `$ }5 C' n. w8 U1 h% y7 l2 [! n- s7 A1 z% G
Firefox 4.0.1 – MAC( S, {* u9 e2 R* A: p& c
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
5 Q/ H) V  ~+ A
2 B$ O  t5 \/ V* A& Y/ ?$ l) EFirefox 4.0.1 – Windows. n; ?* f! e6 M6 C; N
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1# }- V3 }9 J8 c9 _% E
0 e8 K* T. C% w) ^4 I
Opera 11.11 – MAC0 }9 C$ p8 k* ~
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
, D' Q* ^1 @& ?8 `6 |4 t0 E  n
: e) n1 h2 [* y3 uOpera 11.11 – Windows
% m) Q7 `2 ^2 O( MUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.111 X7 u0 u. [7 ?/ r  C
+ v+ Q5 k  n2 H& D
Chrome 17.0 – MAC6 v! m- C3 ^5 k. [8 r9 S+ X1 N
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
; P* ^0 k) P) H  oUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
  u! {9 e. Y2 _) @) k2 j$ J% b2 p' h2 D% W$ s! t, T6 h1 J
TT" n2 x  ]: W4 [/ z, C& H
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
1 L' \+ z7 p6 b( C5 v9 o. |: Y! }. ^2 U. r! n" \
The World 2.x
; Z8 J5 A' P% w! R, G. a$ z# WUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
9 Q% M) N* W0 f5 N( v% d" D) \5 A! z6 Q- X" h4 E2 r/ D' e. f
The World 3.x
. y+ u5 \4 D4 I/ O- P  uUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)- C, ]" b1 c8 Y* \- G4 T; L

% h( x( J/ o6 T3 z搜狗浏览器 1.x
- P, e$ S# ?0 L6 G1 MUser-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)
7 e2 N8 t/ z: t
' d3 L7 C& h4 a7 c% N360SE
. P5 j/ u) q8 \; lUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
" X) G' @5 o$ t  ?5 j/ |0 Z! Z, y; S4 b8 A4 A4 b7 M" M
Avant
5 `. {2 M  S  N8 R$ i* u$ IUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)3 X4 R; o5 @$ M" Z3 s8 ^4 [

  V. _- m" |8 X$ \1 ^( k, bGreen Browser, N2 C) r# v; q! J  z% `
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
3 i3 A" q$ a  p. S: mUser-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. O- a1 B( H" N: k2 }0 b% v

$ f1 U. O# F# s& d  X9 Fsafari iOS 4.33 – iPod Touch! A7 h' P  c7 J
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
6 ?7 E5 l  g2 }9 L9 n9 z& z- w( [2 R5 K0 l. }, q$ f  O0 a( b3 Q
safari iOS 4.33 – iPad+ Q. g7 x' Q- r( w) T# ?9 u) |$ t  D; t
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.57 X7 W% x2 p. m2 @5 j4 o% }
1 L9 U- g8 m8 e/ b0 h6 t& r( Z
Android N1
8 c) z4 t( n, d. k" [- FUser-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$ x* f* J7 q' N. F9 o

. H# h/ _, X$ D* l# [- _/ CAndroid QQ For android7 I' D! d2 z3 t+ O( z
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
1 a+ J  Y: V8 S, W* I
8 ~. O% h4 ^: kAndroid Opera Mobile6 t  k& `8 \6 L2 C) X1 [/ Q9 P
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10  \' c5 t: @' V) |8 M

2 s. |) }7 I. `8 t: r/ YAndroid Pad Moto Xoom
, _0 _7 e- x* i! @" \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
7 ?5 C/ k! Z7 [/ P; z. h- j5 f% ~7 ?7 s( j% t9 G2 }! r7 n
BlackBerry
( m7 z* y3 [. h+ ]; p1 PUser-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! M" x' N3 I5 g) F6 ?& I, i& _
* `1 l2 c! b: {7 O1 ?: W; L
WebOS HP Touchpad
1 q$ m3 L0 u# e8 X6 c6 H# _" UUser-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
, H! Z9 U  o. v# W, `$ L* p+ U& H* d; O9 C) b* }5 y
Nokia N97& A, D& y7 X) M. @2 ]2 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) z- Q1 c8 G6 f5 J) l5 P7 z# G% `
+ L% Z; i& S# O9 X7 ^+ H' h" Z5 p
Windows Phone Mango! K6 x& \2 }1 X8 B+ a6 T
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
3 Z- R' P, Y4 |' n; q7 o
# f9 c4 I+ ^8 _3 Q% eUC标准! d; a1 t' b" X8 V  \! _5 Y0 u
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
7 Q0 W7 D( W5 R+ Q" A9 O$ j( d' i5 J2 x9 Z2 m
UCOpenwave2 M/ {) w# a1 f
User-Agent: Openwave/ UCWEB7.0.2.37/28/999- ?7 y/ r4 o6 R" V+ O+ r5 J: M$ e2 O
( j6 i& G. b! x1 G: o
UC Opera
5 v/ ]+ l2 H' e: R* k2 f: j/ ]User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

参考: http://www.webkaka.com/tutorial/zhanzhang/2015/060421/

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全