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

6 b8 a9 _% u" i' l! X

" g7 y4 I( N1 F5 i' E: F) e

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) o8 z* _3 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 U3 f4 i, t8 \7 J9 q; E

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

5 Y0 C( f$ S5 M5 i: j2 G, k) t9 t
& ~/ R% {6 e& r) u( a* @

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC8 Q" V% ~4 t2 u
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.50
  C% d) p- }' \1 S  V
8 c! v/ s" E1 f3 nsafari 5.1 – Windows" d/ S4 ]# L) n/ g
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
! |( f9 b7 k  L2 ]" X. c, V& `* H/ J0 `8 N4 x$ z
IE 9.0- k. C. X* o& Z3 [4 `3 d* S6 j
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
. b$ j0 W1 Y" K4 p% h( s/ l* N6 l$ G; O' n' s- X
IE 8.0
( P1 H( A* P: k! A3 jUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)( U+ D7 y; Z5 o  I% k, h

- ]4 c6 E1 Q9 L8 uIE 7.0
* @; e% d" u) N/ A; z2 e' @User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
( B8 G1 g' o- G' f4 l3 ^& f3 H
% Z+ }1 |0 k6 T+ }8 yIE 6.0
! {+ R' t) v. y' |% ~8 J# W1 O/ e& aUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
) g1 o" z7 N. h( S: q& c3 G, [$ Y4 U" d6 ^
Firefox 4.0.1 – MAC
4 V3 |3 t+ S3 b- J- JUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
" `0 R2 T' r# t% q: S" w
  y: o) `; I+ ?) Y; lFirefox 4.0.1 – Windows
% e, |7 M; O8 F! J' u+ k* W# A6 [User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
$ \. |: g/ Y8 K3 r9 ]" V: C1 C: e" w( ?' l' {' L+ W' r( Q" G
Opera 11.11 – MAC, |( _, J* i4 C% i8 }
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.116 K; ^/ f3 J* o& V6 e  ]
4 o' P" h3 N+ E! W; m5 W+ \- Q& h/ ]
Opera 11.11 – Windows5 E  E2 G5 u* r% p
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11. }8 _0 b$ i; \  G% v
. j1 k$ H& L; d/ i, H0 o, j
Chrome 17.0 – MAC, H7 a7 x/ R# J- 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、国产浏览器

Maxthon6 @! \8 Z/ }0 d* g- w
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
, }* A+ L1 ~) a+ t" N) O7 o2 ?8 C  R; i
TT
" R! [. R7 f2 a' LUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
+ x3 k/ S( [4 S- i9 D# E: Y( A
3 {9 A( O+ N) X; @The World 2.x
- a% u8 K& [# N1 vUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)* E  |1 z; z) Y2 `2 I. @$ B
6 l& d4 b- Q% |/ a
The World 3.x
2 G& B+ I$ Y3 }" I, \& [* uUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
  e' g( e- ^: k+ [' f0 e7 @* F
搜狗浏览器 1.x
' L5 B1 L9 G+ g2 q! bUser-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)5 ~3 y/ a; y2 [8 b7 j5 b& [
& h4 K' A* V, Q; z2 \7 Y2 u  R: @
360SE
! R& k9 [. Y. J0 jUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
5 b% V. b3 S9 R# \. y! Q, Q
  |+ ]- d: b# L  T/ ^Avant: Z2 P2 l8 k0 H# S0 O, ]
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
" {4 \+ l4 P9 H: S5 z# i; Q: t. M+ ~2 o: B- k
Green Browser, ?  Y+ Q% P; j; T9 |" [
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone# k# a2 ^! x5 t( }% h2 \- {2 F1 S3 ~
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
: R3 X1 A& E7 n* F: O
2 y- k8 t5 M" e" J; Asafari iOS 4.33 – iPod Touch
  ]+ B# q- l! U) nUser-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
) E0 o; N7 d  y8 v
8 U' O5 d2 t8 o/ lsafari iOS 4.33 – iPad4 G" s2 k- x2 R, p0 p
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
1 r/ X/ ]+ {$ J) Y% X7 y0 L* j! R1 N: Z- B, |
Android N1
. I' b# |* v0 n5 g1 w! D( UUser-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  @) a  f- U4 o' c$ P  b

9 ]7 y# A+ S2 p/ e) N$ s( L& @! C8 HAndroid QQ For android, M: h+ k- `9 R5 c  Z7 i: a, Y
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.13 f' E9 v; K9 H
9 b3 I/ E( w5 G5 B
Android Opera Mobile
, Q; l# `6 K  B& D- D: G, {User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10+ n1 l8 m. u5 i- N, y: L

0 w1 U4 {* v. F2 h% zAndroid Pad Moto Xoom
- H, [- n1 h+ \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, L6 y$ K5 f% k

/ p2 l# [/ d( W0 i8 e2 A' I* t% KBlackBerry
) D' e+ a0 D! _3 DUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
, r+ a6 z, L5 X# l; g$ F+ n" s, [+ ?
/ o. `* d+ N2 ~$ [( ?. L& oWebOS HP Touchpad1 K$ s0 |# d+ S  W0 z9 i& t. A8 ~
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
- {4 ~3 M9 |0 ?7 e! }; f  E- i$ L
- ^; ^: V8 \4 e! d! z! _/ Q7 iNokia N974 p- ~8 @- L7 y  g
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% G* O& D  a: B
, N" S1 ]* T0 q! B/ C9 J: b1 ]Windows Phone Mango
( s  H- e# s" `0 j( p; W- zUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
% ]8 A% a! M" R8 ^8 s. o- k! p2 M6 C& a, Z
UC标准) m5 a% K# i, _% `# O! K9 D+ B+ S
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
# Y3 X1 q/ X; {4 V) ?/ H$ N
' |( x. H! @: _: c" |) Y# VUCOpenwave+ N( M2 _4 b" e
User-Agent: Openwave/ UCWEB7.0.2.37/28/999  ^, T: s) ^" N2 X+ g5 o

$ G- f. @* M  W0 l4 zUC Opera
, h2 p+ i& E& v! qUser-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
互联网安全