$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.         ?>
复制代码
, V6 t' f2 `+ C7 O# V# R) R" l  @/ H

% ]* i  S4 e% j  q& n! d- X" c; c

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

7 ]1 l, J$ v! K% w

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

4 n8 M$ u6 _/ D: O. d1 ~

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

" U2 \2 o* G& o
2 S, C2 D  V! I  M

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
& Q! c: w9 w& h/ M( P0 K* yUser-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.503 _! W) s% N$ J' M" d
& Q( X8 y. {$ U# J1 Q; d
safari 5.1 – Windows: D2 b5 N9 \+ }5 c
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
$ g; w3 M! D2 @( G# `9 W; N/ l0 I; d: s, B
IE 9.0
. V* P+ F- I: M) aUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
: z! a, N2 ?6 ~* L& r8 k) \0 w7 G* M2 A# L4 f  X
IE 8.0  c# {8 p7 j+ c: r4 W/ y# s/ P/ x  w( ?# ^
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
& }! Z; `  |( @, M
& _! ^# G* C! ~IE 7.0( G+ O: ~. _8 k7 n- |7 m9 H. \4 |
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
( F3 J+ y$ k% I% i  V) O  T1 A+ h( ]# C/ j4 f! E
IE 6.09 _. L9 t+ a0 T4 w2 w0 J
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)2 [$ @/ }+ n; a( p) q

- U) m# f  k, n3 ?3 G3 fFirefox 4.0.1 – MAC# a5 U& F* B2 S; J0 @
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.15 k8 ]+ v1 F7 s: T4 k

9 Y# _" H1 G% F+ W9 C4 x  ~2 {- }Firefox 4.0.1 – Windows9 t4 O6 h9 E. I1 v% k3 x0 H" e
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
; P% R6 }7 j4 ~1 v: O% K" b
' s- p- ~1 a/ h5 [/ Z& eOpera 11.11 – MAC
( V% S  i7 l* p! `+ FUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
  d1 m; i0 ^, r$ l( f- A  {' @% A. V- \& F* O: G+ L/ i4 D( q
Opera 11.11 – Windows
6 d4 k" H9 I' a+ v/ vUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.118 B" l! J, l' n& h5 w
9 K* @7 U( }$ F) E1 P
Chrome 17.0 – MAC! {/ O* P( b3 Y. n( {3 S! [& Y
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# M' f% h& P* f( ^
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)7 K7 y- J( H, a4 j* b7 b( ^8 X; q

2 {: S* o  F/ q! {3 ITT
" D+ C+ Z) N$ T* M& oUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)- y1 u2 i; R; i8 r/ r# G! s8 b

0 p! V9 G& L: `2 V  ZThe World 2.x' {7 |. X& K% X2 n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
* w1 }, Y+ w& ]' i$ }& Q. k- p! @( G3 o& R* ]) ^
The World 3.x
, A, I8 ~+ a. q* k% Z2 mUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)7 j" Y  V9 C+ ]+ E
4 H; N; Y2 g9 b
搜狗浏览器 1.x
8 @! D0 a% c2 Q4 m1 }3 U1 v: 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 P! M8 l9 C4 v9 g
' T8 @( H/ }/ W8 S, t/ j0 M- \' `4 m360SE7 M# C# B- x" u- j& J/ ~! F
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)" L3 B6 ^+ P; _* V

/ p& F7 H, @+ ]3 C% RAvant1 C% S) V2 |2 r" f
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)6 B( c! ?8 Q4 T3 ]( ^
% E/ _, k0 ~' D+ t" u
Green Browser
& w- l. ^0 `! b6 R% JUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone  a" o8 e& ^8 I
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.52 c- w. ^4 j( D- j5 H( a! F' p
9 j% i3 B* F( ~" i5 `5 i
safari iOS 4.33 – iPod Touch7 L* P" G; E: c( F/ H2 j0 R0 l
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.56 w; F* e! a# e
) x2 N3 v# |) X' k8 z: Q0 D
safari iOS 4.33 – iPad
7 L& p* g, P3 f% \* TUser-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: ?- {* a6 {8 f6 ^
( {/ d% B# L3 o5 }2 r
Android N1
* T3 C+ Y7 u' z5 w9 Z1 y8 t2 PUser-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
, Z& ^1 y, S# l. X& N+ l6 c+ _' U7 h( R8 a& P; ^; @: F$ M7 ?' z3 v
Android QQ For android
5 t" }( g2 K0 T4 [8 iUser-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
: k5 \" X$ [( b9 @& N+ c8 o2 J% ^7 u7 O, h' Z
Android Opera Mobile. t! A0 E+ B- \, \/ G( O+ Y6 X8 O
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10' C% c& _8 |3 E5 D
+ {* a8 S( y: s% B5 W  f0 E
Android Pad Moto Xoom
! ]% Y2 i# |( I6 TUser-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 H3 C- Y; ^$ X$ d& @
7 a( w( z5 W  ^) p+ l6 S1 h- C& pBlackBerry
8 _: J  u* J: i5 Y% hUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
, z0 C1 P- p5 X4 N  P/ E3 _5 K5 ?# {6 Q/ e/ F% Z3 @
WebOS HP Touchpad: T8 v2 f6 ]4 p1 w5 l7 W& N) J: E% p
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, L' i* \* u2 A

# m# {$ b2 ?) x0 w6 E8 HNokia N97
7 `0 |. F9 D9 a  d8 _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) E! h/ l6 u5 _2 S
7 c* g6 m& U2 R5 o
Windows Phone Mango
: J0 v) y/ f, o: L( A! f9 iUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)4 W! I/ [" t' e( I! h2 Y# u
4 a+ e# ?9 ?2 p" J/ D5 U5 L
UC标准
6 k4 T4 T* H; E/ g% a) D$ _: pUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999" w" u& F; H  k3 G) n' q! q6 G7 m
' }- S3 z- r, k
UCOpenwave) g) J, f4 m! z4 F
User-Agent: Openwave/ UCWEB7.0.2.37/28/999& I; ?( m% o, R" }& B' h

3 P" g) ^0 i, o& f- FUC Opera3 q: s& F( Z) S6 y
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
互联网安全