$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.         ?>
复制代码
# h! S2 q; S8 d5 i& p, x

7 n, _) s7 r4 w, v

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

, ~9 C% N/ D0 k5 T2 D1 F

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.         }
复制代码
5 g; Y" B4 c& l9 ]3 }2 l

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


! s% y8 h0 j  Z8 R1 Z+ G6 W7 R
( W( _: e# a6 ?, _- |6 y

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
* q: q8 b4 Q! Q1 h9 cUser-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
! C1 S' d' @' d; ?! J" {3 x7 o* i8 q  ^/ p
safari 5.1 – Windows
- ?. ?4 h- t& _7 b7 s( \; G5 a+ ~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$ g$ ^; N. Q: H" B6 k
* |- c( G( Y7 w5 r
IE 9.0( o4 \0 e( n6 M6 O# s
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;) A& f( _- \8 z% n( ^+ D  S. K

# f& C  N0 T" g/ y- j8 z4 F8 }- lIE 8.0  X. o1 ~3 h. P2 g; d. s
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
+ ~8 i% R% R+ @% X$ ~' Q& B: W) m8 F8 m5 z3 f+ \0 K4 j
IE 7.0
6 w% `$ i5 J# G& u! a6 CUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
  ~: G5 E$ K& C; Y! v3 L8 O# s( H
IE 6.0. h5 R% u7 N2 K4 K6 N+ x
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
  j$ w: S: [# Z: J* R7 h5 N: Y4 u5 Y# X
Firefox 4.0.1 – MAC5 V9 d( `0 o& U. A
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1+ M0 h" D+ I# W

  }3 O% P8 \/ x) R& _4 ^$ I% KFirefox 4.0.1 – Windows( O  p, w3 f0 ]- Y  c6 e" s
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1& r5 A3 W9 U2 b5 ]* N( v9 g3 `

- x2 K2 V' T5 [3 H; O- P, n% p/ COpera 11.11 – MAC& P% R6 ]/ b) Z" ^! u6 {3 O
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
& r) w* a* e, R; J/ R1 @
- U# `) a9 u* pOpera 11.11 – Windows* `$ f2 O4 u+ g5 x0 M
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.114 O! Q: j5 D7 s5 x6 J3 e# }( K3 n, U
8 |: j) a) K' [  {
Chrome 17.0 – MAC
+ _  S5 T' }9 T( sUser-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) ~6 _) g: r/ ~: \7 J" A( N: x
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0), a! i+ w  x" b8 O: R

% R7 @- o) r, @/ i5 M; r, ^TT
1 ?4 L4 e2 X! ?, o7 _  I4 `User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)1 Z, }8 e# N! @

3 y  `% Q" ]! T; ]) h8 I9 g4 i$ OThe World 2.x7 P! w) T% s  ~. o. m
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
3 p& ?# S8 `& r  O) c" ^& G  E) b' Q3 K
The World 3.x
) k6 N& Y. }3 p( q5 B# G9 KUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
4 p! ?" [" Q+ m  o/ D4 J, [* j- k; x# ^+ g+ M
搜狗浏览器 1.x1 a: L2 l" I6 ?8 k
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)
# S' Z6 \. `0 N! G) H9 B$ l8 Y( b
. Q9 g" y1 O! Y: R5 Y  Q$ D360SE3 _) I2 p+ l  Y6 _7 K
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
" a& ?0 ~/ V) r) {4 ?
, z' n) [5 Q/ P$ ]Avant  Z, o7 h: g) Q0 D: [2 L
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)/ W, v* M  A) D

$ m2 y+ r& W0 q$ t; QGreen Browser
8 r& s; W+ }/ R2 V9 ?- KUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
9 M  X1 D9 m( |# MUser-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
' _- f# o# I' ^$ S# r9 T" U
3 K' N( Q, ?. ]: `4 P. gsafari iOS 4.33 – iPod Touch
$ h  f; N! ?6 F7 @( X: M, G7 lUser-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
: X+ R/ v3 z! l5 h
# r6 e$ |2 V/ a5 ?4 A$ H/ e! \3 vsafari iOS 4.33 – iPad
! M" c) q# v& k& V+ {( W7 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
/ {# w9 g4 K: D5 T1 b$ |0 D: T5 \& \
) |3 ^$ D/ ^& WAndroid N19 ~- J* c. B5 V( J4 L3 j7 A" P( H
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 x* x% M5 F5 M+ o5 l
0 T) @1 |& T; L* Y* n# ?6 cAndroid QQ For android
3 Y- }6 `0 l6 D3 t3 f( H4 Z/ _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
& B  S+ O0 w- Q+ e4 N: f- L" [
, |+ _& ?' J0 c# Y" _Android Opera Mobile
, ?7 _; \& P9 X* Y% L3 Q( t+ aUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.106 ~! V) n& D! Y$ j1 P* Z
% Q  c- F- [- G, ~$ x% ~+ l8 G
Android Pad Moto Xoom% I. L) p3 j' Q* ?+ K6 T
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
. @  S6 Z0 {& U: H
" i) y: N/ K9 D& C; IBlackBerry
3 E5 t7 M* q5 d, U. ^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+" B* c6 u0 G5 ~+ U! K5 q: q& }; M

9 R2 X" Z7 C4 U) {WebOS HP Touchpad
& V+ [$ n7 a$ N' PUser-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.08 T  }* O1 n4 L

, i& P) J3 e  D6 P* ]Nokia N970 v$ ]8 X( Y2 |$ X  J
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
! P# z3 W- c# I# ~
- {; s* I/ g' L) \) l( J* g5 TWindows Phone Mango# T, u5 o* U) r5 R$ d
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
, U$ k3 N; f  D/ q9 o
7 u! [6 U6 B2 U; W9 jUC标准
$ H" |- k6 q6 J$ F/ OUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
/ D; {5 q+ p" c7 e
1 n* R- B" P9 \" m0 kUCOpenwave
4 n4 x/ I6 \4 }# aUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
, R3 `% B3 O  a1 d4 u* \$ k1 ]  e5 {' W+ M1 `, D) K
UC Opera6 w6 d, a  _$ }; O# o
User-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
互联网安全