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

& z! K$ s6 N* C$ b

  g  j3 B$ x% ~( l% `

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

* a' G; D) O: \8 N- s3 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.         }
复制代码

' b& k+ z% E; W* x* T. O* [" m5 S

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


9 Q, H6 P* E2 v6 E7 D- ?
" [: U9 Q; x6 X* L0 _' M

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
5 u1 t1 \: k3 A  z& B# OUser-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
; Q- s) j) Z2 B3 U  |7 h, }% k# c4 c# P- B9 `" f, o
safari 5.1 – Windows
2 @- T* B. G6 @+ O* \1 A/ d2 oUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
9 ^: o% ^; H% D! {, H" l
) |* ]3 S1 N: b8 G3 ~5 ^! ?8 yIE 9.0+ ]3 S! `( x9 s
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
- A2 K& b, `1 S7 i8 B, c5 V5 \) [8 ]/ C
IE 8.0
$ z* }/ s( X! Z( M. E# wUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
( B& K. I8 x# `1 }: o" L
- H( S. s, v6 R# P+ S* ^IE 7.04 f3 _3 D+ k7 e5 |$ n( |+ s1 W
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
" C! q4 ]+ i) k- |/ }3 l' f8 b2 l+ B5 e7 n0 h$ [
IE 6.0, ^  [- b2 w' d
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" s# z9 j" {$ y" O
- A3 r3 g* H/ g9 x" F7 q3 F2 p/ R7 n
Firefox 4.0.1 – MAC
& L4 L# b9 |+ A( m* f: FUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
  a6 d% X7 a% H' t
: {6 |/ B# s* GFirefox 4.0.1 – Windows# h! U5 _- f7 m" A9 D+ j
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
/ a2 K: K: U( I5 K7 R: j' |) E
" G! S4 V1 ?; Q# O6 b# L4 @7 ?Opera 11.11 – MAC
$ J/ h: I1 n/ @5 ~+ RUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11+ s+ m& d! {' _8 y  a# k- G
8 {' c' |' Z, Q* v3 d+ q. x
Opera 11.11 – Windows$ l" t4 B0 [' F
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
4 v- E6 u$ H$ B0 ]6 b! w) ?4 q  m, A# R8 i
Chrome 17.0 – MAC: y/ F* N4 M3 V$ X9 m8 N, r
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、国产浏览器

Maxthon" A& S4 `2 m5 G5 F, ]& \# V5 p! m! G
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)2 L# {/ N/ f* n# L; a
$ k; F2 @5 \! i) y
TT
: J1 B. Z. X' h( xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
) G( m  ?& |0 ?" [% t# j/ [9 E  ?- H3 [& B+ C9 a) ^- u
The World 2.x
: a$ \( Q- P  v2 BUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
: b" J8 I% M# t* M& a- R& h
/ G1 h$ f, B9 }% T- GThe World 3.x8 d+ K* g7 W8 d8 s4 h3 C
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)+ W0 Z* a2 V7 ]

" q0 m1 a4 w2 u9 T% S% U; P搜狗浏览器 1.x7 Z' m, H# M9 P  C6 S
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)
9 h$ ^* T' M5 c7 }4 N. r" @& e8 _- v6 U" }. }1 ~$ j
360SE
9 U5 [9 u1 V! \$ Q7 e" xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
& y7 `) r( Y% z. d) H0 Q. ~  k3 r# c: q* R" P3 P4 i
Avant
, c0 c! c7 ~  F: s* l8 i0 DUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
, E$ [+ v2 B- H# \! ?9 R/ e# H; V# Z% S2 m
Green Browser; H1 Z( E# ]) L5 ]
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone( w) ^6 d8 r6 q* Q* T2 F
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
# a1 p3 W- y3 r/ U2 T- }" C( Y4 U: C2 t& u  l( E
safari iOS 4.33 – iPod Touch/ f9 b9 @, t0 e6 M8 L' G9 j% z
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
2 ]5 n& o5 q# H
" \  _1 g* b3 G- C: Asafari iOS 4.33 – iPad* ^6 `: G& r$ a
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; v1 ~+ B1 ~2 W& e) Q' C3 E2 c% w
- M8 U+ V" H0 k6 i6 R3 ]2 h# ^
Android N1
6 a' z& C. b  m0 r! T6 \  W: o5 mUser-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
0 w$ |. x/ @$ ^9 s5 I. e9 I' ]: ^3 @# _7 F3 z
Android QQ For android) u# J$ R; `: P" O) B$ P8 V! P
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
1 s1 N$ f% Q/ L( d- p
: N, p% T% a) c% ^Android Opera Mobile$ ]4 J2 e) S2 ^$ b
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
/ I: y2 x( D/ J* }* E+ k- m
0 a& g! m4 R0 E1 w3 f; oAndroid Pad Moto Xoom4 K: Q3 ?  w+ _# u: I: G. Q
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
3 E$ u/ v6 J+ {$ N. ?
/ G; T$ H# @2 a3 X. g) I( r3 L/ jBlackBerry  ?0 {% F% r' A" \# l' M, _
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+
) F  J$ c: S; O$ p8 |# E& m* N. K
WebOS HP Touchpad
' Q; z; H! A5 s2 M  _8 @7 FUser-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# w) y9 Y: ]* r
! y: `2 c5 ]9 k+ k
Nokia N97  T1 i' a; m+ x& s
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
9 t) l+ ]+ K  _+ t% u3 K* s
  [. \) ?9 Q, lWindows Phone Mango
" d4 W$ R9 o! ]0 h4 r# ?; MUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)- b, P: v& H' @( \

8 _# K$ h( i  o( @0 E5 L" fUC标准' s$ \( X: j4 S- k4 d
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999& w" b  ?$ \( H% j4 C
2 i* T+ i# u( ^* Y
UCOpenwave
$ Q3 @; Y0 s* R5 P& z& e" yUser-Agent: Openwave/ UCWEB7.0.2.37/28/9991 m# V5 q0 C1 V* F+ o

/ f: j, {9 p0 YUC Opera
+ X7 q/ H: a: U/ ?, I4 sUser-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
互联网安全