$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.         ?>
复制代码
, i$ T* A& K- g* M

4 v) a+ s8 V0 E, O5 y2 H% I: [

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

4 N& u3 o6 M3 y+ L! 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.         }
复制代码

8 x  K- u7 e3 Q) m: q) L

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

, j1 v3 A. c" g) k8 k9 ^/ [

" x' \& W8 h% I0 y3 }

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
) l2 \: d' e# S/ M+ ^" 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.504 s, v6 U/ \( W; z/ [) \. E' H

5 k5 L2 t7 ^9 ?# Rsafari 5.1 – Windows
8 K' y4 p6 Y5 g* \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
, Q  b, r9 E6 G# |4 G3 K/ m7 p4 G( h. h$ Y0 i
IE 9.0, J, j' ~2 }' _( s' ?) \
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;! l& `: K8 j6 o  L* S  G7 |

: R# A1 a! I! J3 `+ W; k  F3 E3 ?2 `IE 8.0
8 w* {# e+ b' o( }$ hUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
) \* j1 j$ q5 n  L  H2 ]# w1 \" I
IE 7.0
* a6 M7 n  f: G. }" z) w3 @User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
3 h: Z6 V  i1 e& j* T' V: V8 K; R) J( v# e0 q2 h* z
IE 6.0" `- }( g( j4 I2 z) e
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1); M# m( p! G% x8 i

) w7 k0 ^' {& l! ^Firefox 4.0.1 – MAC
! u1 J; U6 W5 T4 [9 m# B- c) M% cUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
8 z/ M' e" V* C! @. Z1 c1 t! z0 I" y) g# R! b8 X% c+ q9 j
Firefox 4.0.1 – Windows6 u% e! j. c6 j, W: h2 C* L
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
$ R7 A2 I0 Y) f; q
8 i; F( M- }6 f1 nOpera 11.11 – MAC% [8 [) _+ ^$ k& Q1 i+ @0 D4 S
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
) ~7 F$ ^8 k/ b5 i/ Z5 ^7 F
6 ?  u& o- T. U0 I- F( r, [Opera 11.11 – Windows& v$ I" ?6 R2 x
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11. k* l& w8 A( ?" l( a, `4 e6 [
/ W1 e+ L# z0 \) |0 I2 D
Chrome 17.0 – MAC% f. K/ r2 k- }( y# G
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; J0 p/ }; F& A8 H
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
, j# P+ w8 A  s
' h/ K3 r% k% m8 eTT  I7 U3 D5 g5 e
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)5 \7 `* Z3 u0 T" X" W
% `% T) ]# M, D) {7 a
The World 2.x! A# w. ^+ N5 C/ e
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)8 u' L- N. G$ C3 M% Y2 x

; L  D" J8 n: ]) f8 [4 }The World 3.x
/ g, A4 e5 G6 {User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
! ^# i- F6 j% |) m$ Q" [/ @& V0 t
# F; L4 {7 F6 S2 w5 ?, d搜狗浏览器 1.x8 W+ |, G0 p4 x. R- `
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)
1 f+ r4 M# k# E, {: A$ }
. c) R" `2 [6 E3 j+ l5 x2 V360SE5 }$ e$ |1 [4 P! a
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
& @( a% R( S$ y9 O. V* i7 ^! V
: p' A. \- }1 t& e, ~4 fAvant
2 x* d0 z  a4 g- [8 w% P( rUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)+ h3 z" F+ u' {6 d" v
; E! F' |7 f8 u
Green Browser
7 A: ]* o8 y8 f+ rUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone4 [: @5 N# ?. [/ L  j7 K, M  V
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
' O" w6 M/ O( r& g; H. Q$ s
5 r' I' T8 b+ o9 H1 Fsafari iOS 4.33 – iPod Touch3 ~1 g4 W. K/ x1 ~/ ^/ q
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.55 m) {; y' X% t

4 k' `2 f2 d  Y' m1 F% Z, T* U! S1 Z4 [safari iOS 4.33 – iPad) T9 J+ M( O0 X1 g0 {( [
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' k0 c( ?0 _0 \3 X

- U8 ?8 ], F7 Z! ^9 |Android N1
" O8 t) F/ i4 o/ iUser-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) W; [6 L4 V4 o9 z8 M
# r# v; z8 p) m
Android QQ For android5 o" f% T2 [0 z6 q4 H: t) t. m
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.19 a! x7 w8 |3 W8 U, j
% p3 c7 T( R1 x
Android Opera Mobile
7 O! u3 K3 y4 g0 MUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
8 a+ H3 N% M7 K: N4 s
7 |0 P. r. t7 i# E" _Android Pad Moto Xoom
9 w% F) F, B5 [3 h) L- ZUser-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
6 @0 K5 ?4 H! m2 t" r' a' b# v) ?$ F. T# |& n1 m' C. o! x1 m7 [
BlackBerry! }6 b. Y7 }: L+ G/ A- m7 e- ?( o
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+- e% `- _! {5 n0 D: H2 n9 S. e- x6 L, R

3 w' ^0 \0 o$ o/ M' b# dWebOS HP Touchpad" H# Y) c9 `* q; [0 {
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
% r* N. O3 G8 z
9 y$ C; |$ ]$ P) }Nokia N97
; k# T$ U; ~, I3 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
! R0 Z/ X  a- h& ]$ ~
6 t6 j+ a; o( F$ ?! WWindows Phone Mango) p* V0 I% n1 g2 j
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan): G! c6 ~. B1 H8 k4 O  e" y
. k, ^3 O" k+ ?) c2 w* `: a
UC标准$ j1 X7 W# J, Z3 W+ ?& }) \' l7 e
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
4 B9 N! L1 O2 c( F! _: p" F* E" i9 y& T
UCOpenwave. a/ g  s: |" T  y
User-Agent: Openwave/ UCWEB7.0.2.37/28/999
" d4 q9 C: ]) O: r0 |1 `( Y3 _; p% v
UC Opera
+ E3 i  N4 j8 GUser-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
互联网安全