$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.         ?>
复制代码
4 P, E) }. a# }. g- h5 J

$ j  M- N. x% p* k

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.         %>
复制代码
. v# @2 l5 G' I$ j. 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.         }
复制代码

' n! a3 ^) A) D

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


! E  b+ [, B5 D! s: P- _: l( D# C& U8 k3 \. R- i

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC4 |6 ]8 W% F# D+ m; i$ G! }
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$ l! `+ ~5 c6 F

; C' p1 E: t; B# e+ i- usafari 5.1 – Windows
4 x) g0 p; K* E, C" K6 W, f  nUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.509 K, X  f2 h# d7 S& p
) f) o5 f( I, ]/ m
IE 9.0$ [" C& o% E0 X- `' r
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;/ q# y, Y. c" E
6 }# o/ y" e$ p3 @* m  o
IE 8.0( ]4 W* ]/ }( Q% S; @7 ?" }1 z
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
% X( U8 u. o) t5 X! f. W7 D$ b& G# w
2 O2 J% L! O; Q) T% s3 L# jIE 7.08 Y# b# J& |- s# z  ]' C* R
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)! m, n. p6 I7 G: O
6 M, s  V! y8 c2 ^7 Q% C- J
IE 6.0+ s: Y3 U' v% L6 ^7 z4 [
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
7 A) ~' [9 H; Q4 I& ^) [- _# Z- R' `4 k8 {# C; [1 `6 T
Firefox 4.0.1 – MAC0 Q# C3 @1 q5 ^
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1- y# {9 u. x: U( V
+ K, g" n1 Q; d( F9 _, \$ S
Firefox 4.0.1 – Windows
; O4 {( w. k) W+ pUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
# c6 ~- X8 e. N/ |+ J  \6 C# C6 v
Opera 11.11 – MAC
# i+ d) o% i% R  O4 R' j5 ?+ IUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11* v2 B8 |1 z8 G5 n$ r! P

/ H. W& y* z. v# V2 v/ F- \Opera 11.11 – Windows9 A. T% A! d. M8 s5 n7 B' s
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.111 p0 {- g+ c# e

! a, h# d/ r9 y# e. U7 s" n, OChrome 17.0 – MAC
$ [  E! U9 a/ ~! a7 zUser-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  T1 D+ o/ P# `% T7 D, G8 H
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
# E6 b7 f. @0 D% z% ~) V! y. x" D) K7 h+ s
TT
2 K! O& q% d  U  [" |5 {User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0): n$ G9 O+ G% I5 p" ^' G
9 h* P5 }2 @' C8 D
The World 2.x1 e! X2 w7 D9 a, a& V
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
) T( V& u3 d" D
- N6 x9 l7 H* g. q- t) EThe World 3.x! \4 H% A' Y2 h. `8 q: n. E* G4 Q
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)$ v; d) X5 E) ^1 R# f8 y
  c1 X5 {$ t7 k: r6 U% G
搜狗浏览器 1.x
; P2 l- S- K" `6 N7 D7 M8 C4 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)" ^, @: K  X! x% `$ Z1 S" \+ d

' P! s' `* n0 t6 O4 H360SE) |: P" k$ _  b4 l
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
1 G5 C0 J- x+ c8 K
. Z4 j7 F* n; y) yAvant
" g* @% ?0 b5 J$ nUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
! ?1 u3 o: O: s$ [- ]+ G& ?( I. q2 j& m6 @
Green Browser
6 p( P+ l+ v6 ^, T) a' J. MUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone8 n: r, D. w' s6 T
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* C: j# K5 \' T
  a, G/ @8 [. y5 q; m
safari iOS 4.33 – iPod Touch! ~9 m4 \( I" L1 ^* R  r% c0 c
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.58 ?0 t+ ~8 w# A' h/ c  a3 V

( [' G& s+ ^( C# j% k* Tsafari iOS 4.33 – iPad
. b3 {: a' j+ V9 m/ g$ vUser-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& C  ?" `. _+ [% s. A' L0 I3 p0 D  `+ ]( c- W! Z. z- o
Android N1+ M( O8 V; E! p% @2 ~7 ]4 R& b
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.14 ?0 e4 A- E0 C1 M; A+ P
* K# p; I( n8 v6 N" f' H) k
Android QQ For android
( a& B: E& T8 Q" e6 o. p1 t, bUser-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
" [6 u. f7 Z9 R  S! g  W* {* d" j  o  J# z) o4 a
Android Opera Mobile
7 s: ?' w5 ]: K9 rUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
! E  Z6 c4 W* \
* k8 O9 H( K' ?7 ~! X  X" Z# EAndroid Pad Moto Xoom
* L5 t. V, o/ c6 a! h+ \( hUser-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( A/ t% i2 U9 b

; |. X% o* N$ cBlackBerry5 ?+ o" `) b' Q/ _" t9 ^) Q
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# T6 z( l. t( F4 _- N# [- t$ S4 f4 T/ @  i/ q1 E! p
WebOS HP Touchpad4 q* ]7 l+ ?8 Y8 c! Q2 T2 ^
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
3 T+ E4 n% j+ S6 f; Z. C& N; o2 b! E4 U4 J$ Z' t
Nokia N97
: z/ C2 N* U& s( @9 L/ X- T8 A7 yUser-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% J" G4 _" \/ b3 ~8 m& _
. c7 |- O( [/ j7 `: \+ w# k! {3 l' \! S% p
Windows Phone Mango$ I* s" y& r+ W& d) T1 q9 h
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)! i; ?6 O* @4 r- o: ]& R6 i" j

1 M, n- v: h: H$ F6 W5 {UC标准0 C, s  U( ^* G; d! d
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9994 V- H' w/ i/ o' O4 l: g/ a

1 c5 q* Z+ P! c% C( Z7 z* y/ gUCOpenwave( c! x3 z5 r6 q) @
User-Agent: Openwave/ UCWEB7.0.2.37/28/999. E+ R- A5 ^- t( F! X5 c3 c
7 j, F/ A* V! u; Z
UC Opera
' S* x& a/ \# FUser-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
互联网安全