$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 g0 e: h1 q# A


& Y: ]1 l2 e+ t9 l5 W% Y8 U

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.         %>
复制代码
* u6 {' U$ J+ t3 b; R$ p; w$ ~2 E

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.         }
复制代码
9 a1 v% J8 w2 A& Q+ A1 [

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

4 C; q3 T# @9 q" q. [

! e. h0 o+ h2 V7 P  X5 w

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
5 ]. O9 i4 q* g# vUser-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' l3 \2 D5 _( e# j

0 m1 G8 s9 c$ c$ n0 Nsafari 5.1 – Windows
  C9 _- C8 u: {" Q+ F" R# AUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50
" l# w# f6 s% M! U( }. z& ~" e" u1 O0 |& D& o3 h1 B, ^- s
IE 9.09 L7 y& e/ s! y) {
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
( z/ `7 T7 R) O! K6 I1 r% [0 T' P5 L1 w+ W
IE 8.0
2 b3 N. ~8 ]% S. G7 zUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
9 @0 f9 s$ {/ N, N' V) q- Y/ c3 D9 N* J$ r7 \, j  V
IE 7.0& \% ]2 y3 {! ], l, S
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0); k1 S- ]0 K( A
8 l) I: a! V+ n  n: N
IE 6.0
8 s& e( ?' `- k& G( C" G. iUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
6 C& b# T4 ~$ f0 @6 _
: G9 k+ a! t, \# ?/ o1 a1 kFirefox 4.0.1 – MAC
( @/ g2 r, ~* x0 J) ^& m; xUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
2 i/ z0 I- R0 M1 b- G
: P' D  Z! a3 V8 G& \* ]Firefox 4.0.1 – Windows
' p' Z# P1 _+ F* HUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.12 |$ M: f$ o8 D% O4 h, ]4 i$ X

. L* j: t: I0 ~& Q" \5 O. R, I  p% WOpera 11.11 – MAC
2 h# d" B# Z  {2 @# r7 _- WUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.114 W. c: `+ Z  b, S* \
  X; q. X+ b5 g# M+ A5 ~2 t
Opera 11.11 – Windows! Y( C3 Q, w& g; ?$ [
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.115 x5 T5 G3 @5 }7 {( A5 b

, y. y# b9 d$ J5 d! r; S' t0 E! M- @Chrome 17.0 – MAC: I0 s9 m' [% v% l+ H' ^
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、国产浏览器

Maxthon1 }/ t+ A5 L! C/ r% I
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
% }! i6 R4 U* n& Z& D4 }5 m# I" O9 K* k" N0 ~
TT, E/ N! S1 g3 m5 {1 F3 @! P
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)8 W5 v$ p5 z/ e" f6 O. L' `

( w$ I) d+ y$ B5 N5 eThe World 2.x# {! l, O$ s& k+ c
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)- K! B# B: ?  k; R
0 A% C! _# @9 C
The World 3.x
- X2 [1 W  Q" ~- C0 m' {User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)0 M$ e! s- A) R4 S4 k" @
2 ~2 c- ~8 `, W& {& y! f1 X% ^% c# a
搜狗浏览器 1.x" }5 k+ f& g6 m' {' T% c
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)7 f( i3 Q5 L( b8 r; F, h
* V; u" m! L) t) D
360SE
7 X. o$ v$ @/ c! m' u* Y& mUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)  ^/ z9 q0 V# W0 f3 V3 Y

1 w: u5 ~1 @0 r1 h( ^% w4 l, K. XAvant
) R, A0 n# {9 T* u( u' A& A9 oUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser): R+ F- O# v& D& Q/ a
+ n( `, s" q; m0 b1 ~
Green Browser
8 b7 [2 e  S3 @$ f3 ?7 N1 ~User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone" c0 j$ z) ~  t$ n0 {' S
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.52 e$ Z6 \+ f1 @  T3 V

5 B6 `$ [" q, xsafari iOS 4.33 – iPod Touch
4 N; _0 {2 G) F& \$ o' JUser-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 V( g) b4 T% `! l9 P8 |

  K( V# C- J0 f9 r8 `; fsafari iOS 4.33 – iPad0 p1 P; ?. H6 ~
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
) i# K1 i$ \/ S& p- B6 {; j; U+ m: m* A; v; j/ U' q4 ~
Android N1- p1 \- V$ b$ B" C7 B" A
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
$ \* h2 ]9 P# Q. k! ~: F/ x+ r* M5 K: B' s0 u& ^- @* `2 K
Android QQ For android
8 f' {& g% z: w+ S0 S  qUser-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
& p( n* i2 o, L7 J2 p6 h$ u! ~
7 k9 Q3 ]2 q9 S/ ~; ~Android Opera Mobile- \/ e6 W7 i; C+ u
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
; r* b7 x0 C3 A# p6 ]. E7 c5 j  u/ F/ F+ u; C" H0 z
Android Pad Moto Xoom9 G5 n9 y( s9 d; V+ i3 b
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" P9 Q% h% n& X2 s# G
$ c& d. T6 R' X9 w1 E+ W! Z3 @
BlackBerry
7 S( E+ }* \4 FUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+
. o0 a8 N% J4 W" {7 O, t( P! j3 ^- h. s' p5 Y) z* a
WebOS HP Touchpad7 x3 g4 C, G. A2 s
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) m+ I1 R: X/ [8 r

3 `9 w/ D5 c' P1 l1 iNokia N97  ]. p2 {' h$ b  ]1 k
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
; @1 e% @# v' u8 J1 N( S
. E+ N9 N; i$ x3 \% E( `6 U& @Windows Phone Mango/ y1 }2 ?' n+ L; P4 ~2 B0 K9 q
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
$ v5 D3 j, y3 A
% K. h. [  C& J0 _4 cUC标准
9 r3 H! A6 S) x7 `4 b6 G. NUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
4 D, G* f9 n( v7 S* y5 A! D" u! s5 z. O2 I
UCOpenwave' B! \6 Y3 N3 h5 {/ m# T4 U& p
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
* T. _& s* d4 z- F. I! c% d) t4 h6 q7 E
UC Opera  I  E% ~. S  Q0 \- ?. J
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999

参考: http://www.webkaka.com/tutorial/zhanzhang/2015/060421/

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全