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

: T+ f7 G8 O; E2 j: e& }; i


9 s& f" }$ a7 |) N' y

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

0 t- w5 n4 O# u

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.         }
复制代码
. f8 P6 f9 y( _! N

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


0 N4 P7 z: W& r
" _* @# i  q$ K* f% Q$ H. X" }

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
2 i8 g! X' x( y& L( i6 gUser-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# b* p; U1 [, e9 t3 q5 E- @+ r

! E9 q( r- d# p# V1 |; Z0 c1 e; qsafari 5.1 – Windows, w& c# Z- i# D4 W) ]0 b
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
3 o- T7 O; o5 T+ d2 y
0 |7 z( _: h  F+ R7 T) W1 a- yIE 9.0
8 `. _. l1 Z0 F9 IUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
! s: n0 O( K8 ?' {  T) j1 x0 d6 j: c; f5 Z9 U
IE 8.0+ q/ Y' ?4 g& ^; D
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
. a( ^& M: m0 @* ]0 h/ \% ?5 z
9 @- l- U% p( F- i* o5 d, Y$ mIE 7.0  ~8 S" [% x! Z9 I- V7 h- f4 s
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)4 e: l& O2 u( Q4 D

6 K: ?- d; ]2 p  L- e+ H0 R5 @IE 6.0( p5 ^! j- G4 g2 E
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
6 O7 a  T: i* s9 F5 l( E3 W8 f+ e1 E
Firefox 4.0.1 – MAC
4 n+ U8 x; |' X4 f; f3 q, X* p5 XUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1' v- F, F7 `% N) U3 |1 \
- ~& y6 Z* I5 w6 z# Z' a, a$ S
Firefox 4.0.1 – Windows& l) _( {8 l0 a6 f
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.11 t: A" T7 C  e
% D9 {! n+ u* L) ^9 l4 `- m6 r3 c
Opera 11.11 – MAC
& X% ^2 H/ g2 t3 gUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.117 A/ ]$ U  G) Z. {: x5 U2 h6 n
4 f4 U8 S9 I8 i3 }2 [& n
Opera 11.11 – Windows
7 E8 m9 m) U2 q3 U" a2 }/ EUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11" i/ D# i6 W" a; J7 d

6 o% S% S7 r6 I5 EChrome 17.0 – MAC+ N& ?" ~2 `3 B/ x' I$ G5 c
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
( E+ [2 t* r3 ?9 @! pUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)* m9 l$ J/ T/ Z- Q) R9 R  W  j9 @

; }: M& I; v6 [4 B7 K3 H& BTT
9 L% Z4 m/ w  h5 bUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
  q1 z! {' @* ~. `. E9 E
  g  H  _) a6 `+ C# y) o  m' H8 OThe World 2.x9 r/ K/ c. p9 T2 S, D
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
. Z. r9 H5 E' J2 j& |, w2 Q" f9 p: ?$ _0 f
The World 3.x
" |3 B! J, }- z" h1 T* \; x3 h. |/ ^User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)( M) U9 @7 D' o5 v! l

3 ~. L+ x4 S6 n搜狗浏览器 1.x
  g' f' I  ^; F% UUser-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)
* D+ e1 f' s3 ?  T5 A' c" `/ N" b1 \# ]2 ~
360SE8 f  |4 J. C% n- W: d
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)6 K( I$ E$ ^; L! X8 U7 m  ?- w% S

! O# W4 M4 c; r% T/ M2 U# _. NAvant
) i- Q' n0 p" C/ ]) A" UUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
, J0 a( s; z6 r* u9 M# j; w/ A) W: L+ M2 R* a" A5 y; h
Green Browser
8 Y3 g( @) K8 W+ ^; J* WUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
6 N: t: _% ]$ z0 C! D. R4 V( DUser-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, X4 C7 t* W' A; D0 P0 V
0 f, t" _" T# h0 `( [
safari iOS 4.33 – iPod Touch
+ G4 n& x8 z) s% sUser-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
) `, ~  M0 @/ p/ ?  i3 [+ d
; z$ A+ J7 j8 b6 I* Q; ^( tsafari iOS 4.33 – iPad
6 F1 F& _, ]7 f+ J: C* f) t3 ?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, f! ^0 O1 h# V$ L
, w6 S% ~- y0 @/ ^% b& J$ ]& s! \4 R2 N
Android N1, G0 L. }1 q0 T: ^5 a$ r9 ?' G
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.15 a2 ]3 \% {; E6 d# x

& J/ }6 I: g- m% \Android QQ For android
% _: X8 D+ W2 t# p" @' r8 k* I1 gUser-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
" e2 c7 x8 m6 o3 f+ q
3 E- a; H" R. I& ?/ |Android Opera Mobile
, F2 K$ z' I1 p$ \: m' G1 AUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
! [( ]8 ]/ k5 ^! E; S" i' C# R1 `3 i- E% M! r8 f, M/ L
Android Pad Moto Xoom
$ V/ \4 X2 Y' }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
  W; B3 E) ?( s0 ?: _0 V9 B$ W, y& \3 d  n3 E! ~3 ]
BlackBerry$ V! W0 _0 S( f% G. l
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+) a" k6 a; u/ i8 J: f

0 U5 O  a5 f  P6 N0 z- L* qWebOS HP Touchpad. H; W/ }$ W# Y
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
* ?2 a* D* _. ^8 R& p4 l) p
( O* E" d5 f  T' P& x0 yNokia N97  l' W; e8 z5 Q) C, b3 {+ {
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
9 n5 ?* J( z9 o) d1 f9 L6 G- r" J6 R2 n7 K) x. w  K% w+ }
Windows Phone Mango
( m+ E9 ?: D- L5 K# y4 hUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)* G2 v1 N# D3 f9 w# x6 \
7 ^( c) S5 Z# W5 R7 ^
UC标准
7 M$ p% \; m0 tUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999$ a$ r% b6 u- r9 {

5 q; l4 o( t( j; ^UCOpenwave& R9 D/ d- E0 b3 y0 @) ]; ?
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
& o% j! F% ]+ I. V' x; P0 y) V# G+ Z, {  t3 A
UC Opera
: U. B7 `7 Y  I( c; UUser-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
互联网安全