$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.         ?>
复制代码
/ c0 W& X9 k$ D0 R; z( T


$ E! j( h, T* {) x$ X2 p( F; X

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

) x* R  d8 o6 \$ _3 D3 l

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

1 [9 T/ f8 }$ |

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


! h& O( j8 e" Z* p5 l1 I. v+ M: x" X# P  ^  E9 c' _+ h& O

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
* x: M$ Z. i7 X# v% N* C  t6 Q: G' BUser-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.502 C! l* y- ]) q+ G& u

6 U- V1 [/ p) _0 ?1 D& H5 n4 zsafari 5.1 – Windows
0 B: [3 Z6 ]7 c0 R$ @7 ^& y& }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+ D0 z! N( j6 h+ `9 h  ~& _7 Z0 M

' l- O3 H* z( I8 @0 sIE 9.0
0 p' J2 D0 ^! t$ s. V; ]User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
& [  ?1 k& K/ S" h  z1 i/ x
; d- @! W% S$ f( |IE 8.05 o$ J! j$ {; U: _5 X
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)3 H9 p/ ]& a% r3 b3 p3 p; q/ j

1 }7 q+ t, u) \9 r8 D9 g! _$ FIE 7.0
4 d* n) h* N/ w" cUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
1 R# z8 }& r* s( f
% i4 g( j7 q7 r. |8 hIE 6.0
. Y  H( a: h1 H. T$ B. i0 v* iUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)/ v+ s  d* L4 W; ?4 h$ {7 [( u
8 h+ W! X3 F- `, B1 U
Firefox 4.0.1 – MAC
2 X/ V' A: ~/ W8 l! p$ f! t. wUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
& C  I! w) Z  M5 m0 \; f! [% W- O+ V- L
Firefox 4.0.1 – Windows
' w: ?3 u' Z: f1 RUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1+ [) g8 q/ q! X+ e5 O' I

* P  a$ \3 |$ C- i( |+ ~( aOpera 11.11 – MAC9 K% G* U" `- m( a
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11, b& C. d) }9 j( H2 X! x8 L

0 g6 g: F' Q# KOpera 11.11 – Windows" I  y  R) V7 ~( O. p+ ]8 j
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11% a* _  E- O; b$ D6 T( p( f( B9 ~

0 d/ h1 I- k" y9 B( |. yChrome 17.0 – MAC0 d5 S* l& j- }# {
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
& z+ _) n5 }! L. j( ~% NUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
! m1 F& q3 ^& W6 ^+ L& u6 K& U, v8 [3 a% o; N9 ~# C
TT1 I7 }, V3 `0 @: w
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)  j& w% G$ w$ T# l
" b4 r9 F. K5 H8 a4 I: n. b0 W
The World 2.x9 U8 X1 b. |6 \# F
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" v) `4 y+ ^+ [. c( D) ~
4 P; ?7 U" t7 {/ f
The World 3.x
# ~  @: C* I# |8 {) WUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)4 g/ e2 E# N/ c1 C

1 [' T2 y+ Y8 i; J3 z$ }搜狗浏览器 1.x
. i$ D/ @* ]  Q3 A. pUser-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)2 z' r. A$ o5 ?6 m

( [( d: A. d  M+ g: I" y$ Z360SE
- F3 ~2 J0 f. T9 \! T5 {" Z+ {User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)" b. ?& b5 K7 w. [$ q% t( h
% T7 a0 k/ `+ X* @
Avant0 w* K+ S+ w: g4 t7 j
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
0 i5 ]- L8 y; W( G3 H0 [' j- c
* H1 b3 J. G2 w4 j8 MGreen Browser2 Y) L- P" |* ~& x4 A1 |9 V2 E8 G& e
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone: [; j# o2 C1 j7 A6 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.5
) l  a( A( q% t: R+ k5 n+ u# a& g) s2 m- Z5 W
safari iOS 4.33 – iPod Touch- Z" w) v7 J, \5 n& v" Q' {
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
5 Z- i1 S! k$ i: P6 ^
: b. S! ]! Y$ X2 \( P! Ksafari iOS 4.33 – iPad
# r2 z1 F7 }  a, E# \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
# c) T* y$ ]. x" b) T- F+ ?4 n
( E, a! R3 `  ]7 I" I, [Android N1
& Y- E6 k0 S0 ^$ o# U' 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.16 w) z* m" r. N) H9 {, N) I

+ p5 D+ W6 C. P7 T. a% _( uAndroid QQ For android; J& `8 J5 Y5 ]: k3 X$ W3 l
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
* O3 A7 A' e8 B  L2 u- Q0 W* u& _/ h; e: w
Android Opera Mobile
1 Z0 C$ D: ?+ _User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.104 j! Q4 O0 _+ y* Y# \7 |
. q. L1 O- y! p
Android Pad Moto Xoom! h- T7 @' C. |
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
$ H1 G$ ~. d  N5 R
4 J# b: R% E# @BlackBerry
* ?8 g2 e1 v7 f+ p5 j- {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+
/ x# F/ m9 o1 c) }4 N4 q2 L
4 ~* ]' t- T2 a2 A( ~WebOS HP Touchpad2 M8 \8 n7 c' e0 b" I5 W; X
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* N6 ^! n. ~" P, A  l* H

6 \7 A' h( \8 z1 n$ }Nokia N97' P; \4 |# [( R) c2 ]  H% E" y: a6 D
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
0 m/ `7 Q+ \) E5 v$ {
' m1 R/ v5 k# F! Y2 W+ EWindows Phone Mango4 S, C8 S) _; U( x0 M0 g, X
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
$ B: C+ S% a6 W# q
; z; m( d1 ?9 ]( q  z" s, E, X5 QUC标准
4 K* F" L' k( A4 b( G. T1 d% SUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999) O2 O3 U0 n. r5 B& m& |

# v5 `( ?# n& M( O: |0 z! UUCOpenwave
# j- L  n( K! T  pUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
/ V0 h6 q$ U( i7 u, ^+ H1 y
; |7 g. x5 _/ \7 C' ]UC Opera  _7 x0 z& W- s  {& }5 o
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
互联网安全