$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.         ?>
复制代码
* w3 v) O6 v% o0 b: K2 F


- |/ T' p& X5 `' d" n+ H* @5 W

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

  s- d. B' s- k$ A- N

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.         }
复制代码
* Y& m+ i/ h( ~+ h# {

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


! N! m/ B& V' z4 t, u+ ^4 R, E7 l; ]+ w5 B+ J4 t$ d7 q3 F

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
7 Z4 ~! v/ [7 \) ^User-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.505 j8 F( V" J0 d0 B

- v- N; T  E# K8 Xsafari 5.1 – Windows
1 @' e$ v( R+ T  [4 [. s# nUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50$ H- v. f8 U1 w. A
, Q& i9 y+ u5 R8 E
IE 9.0
, q& b$ o, j! ]6 z) GUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;/ R1 z( s1 D9 Q# e/ N1 b

% U, s  h! _  f5 a# W: O% [IE 8.0
; f5 h# w. ?- p3 I9 V" RUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)' D7 l7 Q. \0 h7 R# @: E4 ]/ N! m$ L

! G) w& h# k$ T: fIE 7.0
4 I1 T& S$ _, I) \& C9 n% vUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
6 O* k" S( t: N& e1 y5 M* g# g& H2 Q+ i, M2 J' G* e9 Q
IE 6.0. B0 u9 {, v- }& {. N1 x- R+ T
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)  ~1 i1 ]6 D, }3 d8 `1 b

5 Q9 ^0 l6 Z4 g5 H/ tFirefox 4.0.1 – MAC6 ]( z" {: M6 n! r" x. S0 a% M
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1' _# l1 S. I7 Z9 o! X
' K# F* K2 u5 W6 f& o
Firefox 4.0.1 – Windows  @: i1 |6 n( u; l8 h8 ~/ k
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1# k6 C- A; [" L( }) H- r

1 e0 [" l- k) k' ^) p- [Opera 11.11 – MAC
! H* V. x. ]  `+ d7 aUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11' J, p. d, }) p$ S
; i8 {* y' i# }  O# J+ I, h
Opera 11.11 – Windows
* w) b+ u# h/ U" @$ F( UUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11! e% K6 |8 y# ]
; {2 A) O- B  Q$ ?% v6 X
Chrome 17.0 – MAC5 m. G5 ]0 o0 h
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、国产浏览器

Maxthon7 \9 Y: w( N# n3 a: p
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)  H. O; p3 p2 h" p2 I% q

# I- R! Q4 W, B  V8 Y( {$ }TT
0 D/ J8 {0 G6 b1 YUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
: ^. r0 D) `6 G1 k& `& A; \" M% m) A3 u) ^% s6 M
The World 2.x! u' x- _3 m# o( ?7 x
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
- u8 g, n% G( w1 R4 S- Z2 T# |- `
The World 3.x, @) m, Y: M- O' \' _" z5 r( E
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
# b  `! N3 x( v, x# c7 X2 x
# d( {& }% y! B/ J搜狗浏览器 1.x
& G' G) _3 B! V. hUser-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)! v# t  \4 u! `. E# y

. |. c* W9 ?2 E* C360SE
: @* F1 y! v0 N6 HUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
" z; |# v/ F, J: e) a4 Z8 q0 V! M1 [2 g
Avant
) u* X* u" ]' b" D7 l9 WUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
  N. r" h9 L" d$ A5 r: ]$ o8 \) e& k' _
Green Browser
0 X( Z3 q9 p0 L7 B! {- V4 a# S0 g3 sUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
% u3 w* Y9 J, z" d& QUser-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.58 Y: V3 l, b  L7 N% M" m

+ ~% G3 U! z3 Z8 t: V5 M* jsafari iOS 4.33 – iPod Touch6 A/ X9 ~$ e& T
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
4 g' k9 L5 m8 B" W. R6 |% k1 C9 N/ Z3 y+ S! `
safari iOS 4.33 – iPad
8 |- _3 Y3 c# l2 l' GUser-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
. Z. t+ P0 @( T8 p* M
! Y. U/ F! y& i9 g' x$ E5 W+ FAndroid N11 f3 k; e5 O+ ?  F: s1 W8 F
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.1
9 A. r& ~" I9 A9 A; b9 m3 C4 m; `, C5 l5 y3 ]# C2 _/ a' E' [5 b8 X
Android QQ For android: V+ F. m/ v) n- u
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' I$ n6 ?5 M9 K+ h
; c( S; F; H! t
Android Opera Mobile
, S* g9 V# m. s# N& NUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
7 \" L% s/ o& C+ f5 i$ ~
# z, B7 d  v  A; Y6 V1 eAndroid Pad Moto Xoom
5 P+ N  z% e9 Q! `3 b0 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.138 q, @  k, k" ?
$ t' c* L# D+ B. n: l: A$ Q
BlackBerry
' W4 c. D  i8 eUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+( }0 k" o, r5 T! y
6 z5 j: _  b4 l* O+ O% B  ^: d
WebOS HP Touchpad3 s: u$ @9 [$ \' b) E
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- O  _" H, M+ F3 M1 X8 I2 ^

' ^) n4 H! t! z! q  U  l# qNokia N97
; q2 g! N3 i5 J! s8 P& Z; Z% ^8 |+ S. LUser-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
# i0 m/ }# `3 n* z
8 U0 X" m  t  |4 P( \4 JWindows Phone Mango
6 P6 V' L, ~! [* j9 {+ VUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan): D# g! K4 A1 E+ ]. f4 n* Y& q# I

, M0 Y, y3 t" s3 YUC标准
! a1 A5 h3 b: w& ?. v1 a; wUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999  O# F9 e2 R1 s3 x0 j. ]
6 O* E' z. _/ g) k
UCOpenwave
( w7 s3 U+ I; S0 C7 yUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
! e  g* `0 d) P& L, I7 P8 n  `' `* P# e0 z% j6 s2 E3 Y7 b
UC Opera( ]! i3 ?' [8 q/ |/ I$ @; a
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
互联网安全