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

/ i1 v- d2 ?7 X4 A' g

' q3 P" k& ~5 L" O; 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.         %>
复制代码
9 x5 W% F0 t/ ]+ J$ I; u7 Y

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.         }
复制代码
. G" \( l! P( t9 [7 y' ]% }

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


& q" Z' q8 E) j& D' }+ U/ T: K" ^$ f, J6 |4 F- K

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC) ~/ ?# I, e9 V+ Y1 I7 M4 I# z
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
3 `+ P: `& V& e2 g4 S" ]% K4 O( n' `8 a1 Z+ \
safari 5.1 – Windows. y& q  \1 a8 K# I9 L; A2 \
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.504 ]+ P# d# f* e, W' l
; }1 s" L; L) j
IE 9.0
2 q3 T; ]4 k( k$ J$ h4 Y: dUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;  D/ l  w' p0 a+ ^# t; u+ w

7 Z8 {  y1 t6 U+ Y/ Q' P# d/ YIE 8.0
7 F6 i, Y& ?, y& h0 P# sUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
, v5 ^+ h9 q+ [# ~4 s. H/ y" d1 c5 \3 A' a9 [+ b4 K/ K" h' [8 E
IE 7.0# L! S- k9 P$ P: \
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
, @: Y, e& ?% G3 i# J# E
7 o0 w' |. s4 C3 |IE 6.0
: d1 Q: |2 F) H, x9 KUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1), m9 D7 y) h9 B+ n: a9 j5 O+ d
+ E! K$ d. s, \0 N
Firefox 4.0.1 – MAC
9 E; i% h: Y+ v- p- ]4 L; u- N4 dUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1: \- A( I0 t% A; S5 @4 l
. A6 \8 R+ d9 E
Firefox 4.0.1 – Windows) }7 C) ]0 Y4 w: z1 Y
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
( G5 x1 j% h& X6 ?8 }$ V* P2 S) x0 J; t& G
Opera 11.11 – MAC
8 w6 c7 y4 j5 }! U/ qUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
$ a" K5 C- p4 i
9 G/ A) s; i, B( LOpera 11.11 – Windows
8 w! F$ \9 a0 }User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.115 [5 E8 b- f4 k+ G8 q# |1 I3 M+ E
1 ~! O: H. a) h  q
Chrome 17.0 – MAC8 w! Y' S& d6 V9 a0 |) ]
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. c( z( a' L' V; e/ [1 Z) _/ T
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)+ F; K/ h( \1 b5 j1 ^+ P  j

3 x* K" v" _& `5 Q3 r- @# [1 {. BTT$ j) M; c$ \* y
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)& B6 [9 U+ J# m: c

6 y4 o, Y( q8 d9 e3 O6 }. q1 @+ rThe World 2.x2 N% e: L, A0 U7 T$ s
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)! ]4 }' o& l" ?" y: z9 v

$ _: J5 Z% Y! G- G' ^* U  f$ KThe World 3.x
* `+ D7 ]9 x$ C4 @& N2 Q8 BUser-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)$ [& V, v6 `: R7 e
0 t+ C3 c8 W) _8 T
搜狗浏览器 1.x
; K! K' X* P" P, X* L3 d  E  KUser-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)% x( D* M; y4 ~' l, O6 X! z5 G

% l3 d  Y1 {" U% D: x360SE2 r0 A+ N- L% A& f0 \
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)1 g2 m/ ~# e. R0 h* e9 v7 ]
! P5 B/ ^5 E3 ]! T; q
Avant3 N5 |! R2 f; g) L. k9 `0 R
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
/ P! g/ H# F- X4 D5 n, E  S( T5 `6 _( v4 i5 R, s5 K9 Q: J: K5 j& m) P
Green Browser' N# d; o: X5 X- j0 t" F5 E
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
4 Q  O1 }0 u  }3 xUser-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
0 T& u, J! w- ~
  H6 I" L- g3 C) J+ b, c7 p5 U0 a5 bsafari iOS 4.33 – iPod Touch
6 C3 r1 K7 {- B) H7 w+ Q) ZUser-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
& E. a" s" O5 H! N; K! C( H9 m) a' J
) T+ j6 N% W' Msafari iOS 4.33 – iPad2 D2 w' E9 X1 s" J
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
! f: V' ?6 X) G- [; _+ Y
4 }  t1 H6 Q) V1 l* A4 b2 Q/ T5 fAndroid N1
3 w# y$ R5 {' C, w, y. _: 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
0 c0 ?! X% o% F0 S/ \7 n- N  ~! K8 m; H
Android QQ For android
( ?3 S% o/ g( Y, \- E  AUser-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( L3 a- n1 v, ^( `- Y7 p
2 A9 G0 b; |! D$ B
Android Opera Mobile, ^8 a7 c. D' I
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.106 a2 W9 N. b3 H+ q6 j2 v

5 n" }% l$ f- t8 MAndroid Pad Moto Xoom
# l$ R2 c2 D. J- oUser-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
! g& D8 m6 |  M/ ?1 X
1 y8 l4 [. G8 g% v/ \BlackBerry
% z0 l7 Q# b, W, }2 CUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+: M( `* F, }8 ]$ a* A/ E

& b! S+ ~' ^( |: m- f: iWebOS HP Touchpad
' T( D! j9 h, F: n. EUser-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
2 s, ^9 Z6 G, [- q
1 p2 R6 }0 r2 P, j6 eNokia N972 }6 g/ d; A3 h# J" u0 p
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
* a) H) s" X5 Y, ?3 L. q6 {. n8 t8 [( c2 t( z- R5 ]7 t
Windows Phone Mango
" D4 [2 ]  w' T) N# lUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
2 q+ A' h! F/ g$ X: B' c
4 }( }5 m+ I( d1 M, LUC标准
7 M. ~6 p! b6 e# a4 z4 n& cUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9999 b1 L% ~% x, I9 `1 |1 Z* _; M* n
* U9 Y, \; ~  `) p3 `5 J7 b
UCOpenwave- I: l0 M% d( ^4 O' @: J% d8 Q
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
- F5 v" h' w7 K0 F, h" v5 z- }1 E4 j9 X
UC Opera- a2 d" r% Q+ U: A& L
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
互联网安全