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

% ~3 N; p7 s& h6 ]

4 S: _9 I6 U' w+ O* i; n

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: ?9 i* j$ m- L) X

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

* e0 F* b' v: [6 a6 z

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


* _, S4 y' p/ x# X" P4 ~5 o# V! p2 J

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
; @. B3 W1 r- |" }6 z# d1 o9 r8 s5 qUser-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
4 a1 ?& t. j: {% [$ ^2 k2 }+ i! U, F3 L  L) g
safari 5.1 – Windows- F, a/ O7 o; F/ `
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- ?. A' w/ P5 x9 C% u& o

; T6 P# e' E& A5 F; L9 BIE 9.0
) q  t0 X* Q, y/ ^  s9 H$ B& g2 a8 cUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;1 y! D2 h- d$ P+ [: s# l

( ^4 d7 V5 S! H% g' rIE 8.0
; C' B# \! q6 T3 TUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
% T- ?. u( X" V, ?* Q
- Y: y+ P  {6 [6 X) `2 y9 }IE 7.0
8 X" V( o) v( R' yUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)/ ~* E6 s* r3 A6 X1 P) H8 L0 P
) G! }" C* O6 v  @- }
IE 6.0( H+ ~2 a: G) C3 D8 d6 W* m
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
( f# a" t6 `  W! m
( s  g' u2 Q5 U% |% p1 E* HFirefox 4.0.1 – MAC
5 B+ ^6 o2 j' @8 o" i: g% mUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1+ ?* p5 L( R1 `

/ V  \3 o: W6 _, y# M* WFirefox 4.0.1 – Windows
. q- L2 f" m5 S7 @! T0 d& ^8 ]User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.12 f" R4 L8 a, g& W

$ a/ y; C2 ?! Q6 @Opera 11.11 – MAC$ q+ S5 q. q2 T: \7 _
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.119 F7 j& Q3 y4 K% H; O( j2 B

0 c7 C4 ^6 y( D; M4 S/ n" h; q3 OOpera 11.11 – Windows6 l& W, Z! i4 E" m' e* {# ]
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
8 u8 S0 t# t0 Q- K- Q& B5 l* n3 ^  Z5 d* f
Chrome 17.0 – MAC! m5 C8 R% P& k* C# L& D
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、国产浏览器

Maxthon2 }1 b( V* L; x
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)- R3 B; R% X% L6 h( h& R1 h4 F

& ~6 Z8 b/ A  @. Q/ ]! C$ E' kTT
3 _  [' \  j9 e" |6 R2 r6 d. P' Z2 AUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
( j! n, E0 m+ P1 u
) |5 }  w8 B6 |) dThe World 2.x
3 n* D/ q" q# M7 j, i1 tUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
5 k& d7 O8 v0 Y2 k  {# Q" E, Y% Q" O
The World 3.x3 K- d$ k1 O! C$ J/ q. {* O
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
& I5 U, Y+ K8 S
0 F& f* g* z' G9 p+ a搜狗浏览器 1.x  t2 t; w1 D) {: m
User-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)
' |; O+ a! w3 `! ^% D& H- W* }+ K& U7 `( l8 ~
360SE
( N- Q$ p% C8 C' e, s* _" a# a; T! NUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)6 S4 H7 o+ T, {6 n9 w. _: a

( C0 K2 @9 _2 j* e6 S; dAvant
/ ]" ^4 b- O7 _" T4 ^, z7 s8 ^5 ]3 PUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)7 _& c4 x% r5 V# l" {) I
+ K& O2 |* }& u
Green Browser) r+ }7 D8 Q2 _: `$ B
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
" ?3 w# G1 C' ?$ K9 c4 L& R' k+ lUser-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.59 d; v$ K5 G" s$ }

  x, W, t, }( Z* `& m# Tsafari iOS 4.33 – iPod Touch# o, T1 `% J& B6 l
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
( g& r: ^2 ?! y' C* G+ \" q4 f5 n$ Y1 ]6 ]
safari iOS 4.33 – iPad; L. d8 I5 f2 n5 Q' H: s8 r% B
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
( R# X/ j- l( e2 K/ N+ U& a4 O' }, U' F8 J4 \- P, G3 t) i
Android N17 P% C/ U1 q8 P4 G6 u( C: Q. \
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$ q* p) Y9 J+ @8 y$ ^  k

3 b1 w, W) }2 Y! A0 KAndroid QQ For android
& Q# ~! [% R) ~/ R+ C7 xUser-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
+ e& m2 l. k; t# w5 V5 H5 U  r( b
! e/ o# F$ d& uAndroid Opera Mobile" y% V2 P8 f: G! s2 D! E
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
% l! q9 N- v7 k( D4 ~! t
& Q+ r. {7 Q7 ]8 f8 ?$ Y, bAndroid Pad Moto Xoom( h0 y9 U( t1 j! a# 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
& Y: }$ ~( U" D# o
4 ?0 n) p- M1 ABlackBerry
1 `% ?1 t2 c+ [& O* U/ bUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
( N  r  ~: H4 j3 U5 ?
! I* m5 s( y5 z' C- N' \/ Z3 f3 mWebOS HP Touchpad+ Q3 {* F9 I7 z) B: h! l
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
6 O7 B: o+ A! d! R1 C5 T; a7 P9 p% T5 u! T) [8 Q
Nokia N97
" e7 V. w3 t. Z/ V; sUser-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: w$ Q- G" n8 w& P8 W5 D9 `. ~
, m& [! E3 T5 T  {! [; {+ ^
Windows Phone Mango
. f5 t1 T: m# [User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
& R6 `+ R# _1 w2 @6 C: ~) d1 A$ o2 ^2 w& I' o# P
UC标准
8 S! l3 |* H- b& Q! `7 \User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
) v* L+ _. |' i; c: Z, p' U# u+ I- B9 ?) {
UCOpenwave  B" t7 w. d8 w" y" r
User-Agent: Openwave/ UCWEB7.0.2.37/28/999/ }9 D3 K/ u* f
3 n" `2 m  E) `2 ?% o: ]
UC Opera
1 l/ e# p6 L3 ?8 DUser-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
互联网安全