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

# N5 {$ [9 s- ?


. ?1 c* Y& {/ \8 a) 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.         %>
复制代码
' H. I- w; V/ Q+ i' }

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

3 i+ a# i: H8 j! k% v7 T

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


  @7 W. O+ z$ \8 v5 w# E; t* l0 T) p( ^% }3 w5 V

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC6 l1 Y2 R$ {6 a
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
% \/ [7 D' t% S' P$ x* o+ ]4 K  s; ^* m
safari 5.1 – Windows& u, `& S4 i5 n. z4 d6 G/ I0 f' j
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+ y4 ?, E6 K; s' b
: B$ G1 C+ F! o
IE 9.0
  ]6 J  _' Z/ W, h0 V1 I5 H' A6 RUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;- Z# L& Z- B# B
. X! X* y, N6 N
IE 8.01 I4 N- J% i# W3 a7 U' Q; x6 m
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)) R8 W0 ~  k4 `2 r; b$ h  _6 Y
+ ]1 a  W$ O9 q; ^( A) T
IE 7.0% l7 F9 s. S* H! o7 l# ?' l
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
/ f% L. C. J# D/ _1 S: ^5 w9 H; _* P  [' L' f: b9 |
IE 6.0
9 @" R+ b' w2 tUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)! j. C0 l) x) z. U/ i0 s
: H0 G* y4 C# S3 A' V  Z$ v+ A
Firefox 4.0.1 – MAC
5 e; e& e0 f& i4 ]6 @$ \: p4 VUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1- _9 ^2 D, P' B. G" t: m

) @/ A9 ~2 D; f6 Q# v$ @! v! x' SFirefox 4.0.1 – Windows
' [- ~$ `$ A+ a% v4 E& K! D% I! GUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
5 n9 t9 y' C, {% c0 g2 ]) B( B
* C3 k* U4 `+ h2 [- S3 LOpera 11.11 – MAC; A0 b8 D0 W1 f& [$ }2 \$ |
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11- m, [' ?% G; J7 \$ M
  g  Z5 @; C2 S& ?6 l: u% i4 S. {
Opera 11.11 – Windows
! ]+ \2 N+ a2 o2 r! j$ jUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
1 N4 o. a8 O8 o5 h8 ]( U, U' Y9 T6 o* @, N+ y$ H6 h6 f$ Y, z
Chrome 17.0 – MAC& E# m9 P* p! ~% e! 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、国产浏览器

Maxthon# \; i. l0 j. |
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
. M4 v0 c1 V7 a# u5 b
& L/ M. }& a4 n: T: iTT
1 f0 m! Y; k# DUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)# n  V& {6 ]- Z% E4 l) ]& {
1 v+ g- V; f0 Z* v5 |, n% G
The World 2.x
/ i) v& E; Z! Q  WUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)& z2 W3 X( e" J1 m# f. d/ `
: B& \) o: b% d0 u% O
The World 3.x9 O7 T+ p( D- Z7 G8 N7 u: P
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)1 H5 G) u  G; v$ u
6 Y+ d& y4 d, P, i# e+ K. q
搜狗浏览器 1.x
* \" ~1 J+ h% i. \1 m% dUser-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)7 y, p# Y. A! w0 Y: f& O
" C, E, m: n& L% T
360SE; l! _% p- w# t' D* a3 q1 D
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
, I' N' I. i! M( K0 h3 ~6 z% v$ g- |+ I% _
Avant
0 W  u- b0 I" {) ^- _: RUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)1 k+ J" M. V( F( d; F1 h9 a" ]

& `) t3 E# O+ F) Z+ S. o: W* }, mGreen Browser
+ `- [% q0 |4 E1 O4 B# J% ?User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone9 M! a& v1 Q' r
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
  U* d# V' D" @, c+ n% ~. X7 O& B; J
safari iOS 4.33 – iPod Touch, A/ [9 k# X5 _" f/ U$ B
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.56 ]9 \& O* H4 F3 S0 ^$ ?, C% x0 B
  F% q+ g' f/ }" X8 |, W! G3 t
safari iOS 4.33 – iPad. x5 N& H' T: \3 Y
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
  P& y) ~) J1 J& {5 w, O8 t4 v) d' N, m% N* v; K. y. z. X, [
Android N1
2 x2 [1 p% z+ ^/ W* kUser-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
) I! r) J! z- |7 {7 ~* x$ ^* w; \: _5 p4 Z2 {( B+ L! @% W
Android QQ For android/ g/ m( o, @0 u$ O
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 g  C  I  F* V- E+ P  a9 {+ J2 v) }0 l3 w  v1 ]9 A& l
Android Opera Mobile
  b/ r$ A5 J& S) m. y7 w+ `User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10& S4 `" R5 J/ u# X/ E$ @
& L4 y/ ?- f: @- |# i
Android Pad Moto Xoom- D% P3 @9 S; C4 a, x
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
2 k7 Q* e5 p- P- A2 l4 `( ^$ `) Z# H6 e% r9 S" E
BlackBerry- _- z' @( B: Q2 G6 B5 a# C' r: y
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+
7 v& q, t+ ?$ h4 o+ A
8 E9 d, U* q/ v% O3 w  t8 ?& F$ r! ~WebOS HP Touchpad6 W* D: Y1 u  I8 U0 j" X  B$ y4 a
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
  D- R9 P! g9 v+ @8 [1 a, ]
. a7 \1 M9 h  L  _/ r2 JNokia N975 `1 N$ L. |- c& C4 R% A0 n% H
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
* f* ~6 O5 b9 t7 p: r% @, f3 z  [- H1 }* A! d9 F
Windows Phone Mango
) m# ^- [& m: ~. l% d' k; LUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)6 x; X$ n  E. q$ a  i" j! |
7 ]# c) E; k7 D+ ~* p, m% U
UC标准
; n/ m0 `1 D8 p  @( O$ V0 O/ kUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9998 K2 r' m7 ]4 g

' z; Z$ t$ x2 @: y' cUCOpenwave1 c( P6 F9 i( G) [; h
User-Agent: Openwave/ UCWEB7.0.2.37/28/9990 \5 `2 p0 s8 [% u2 q% Y, L

! @! M7 i0 \& ]/ eUC Opera
$ C+ ]6 [9 f$ _" ]( XUser-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
互联网安全