$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.         ?>
复制代码
/ \8 X4 R9 l- [, p8 M- t! d% K

( S& v+ [; X& w4 H- g

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

+ f5 [9 Q1 y( r' p0 t

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.         }
复制代码
  T7 P: d% I2 p) \

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

- I. h6 ?0 p1 A/ z
: |5 g% A2 Y0 |# x) H+ _

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC# k/ c2 e: B, E7 S# e5 j
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/ X  Q$ }& R! @7 {
% F, M9 [5 t+ ]* T1 W
safari 5.1 – Windows: z8 o# R7 p+ ~5 @- i& K
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
2 d7 q/ l' ?" g7 R  q: o
1 C2 R2 c) Q/ h1 pIE 9.0( Y" U6 v2 ?& k6 s! `" [9 C% }- u7 R
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;8 N5 O( w7 x! V# C# X

( T2 ?% w9 M5 ]0 c" DIE 8.0
6 O, l/ U. N/ TUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
! g- ^3 T# ~5 b+ h& H& R/ g/ `7 S( W% L( A: m, i" w) u% E1 S
IE 7.0: n1 o4 D( w( V" }* m3 y
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)- D( m7 P4 o5 Z3 J% q/ c8 z$ ]; C
+ p& c7 |8 A4 ?- ~: [5 R! H
IE 6.0
6 G# y, f1 z5 f& l" T8 [User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
+ \! x& n5 F+ g8 w1 ]- T% Z( p2 w, i2 V: u
Firefox 4.0.1 – MAC2 x& I5 G- X* T' E- c
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
- Y" e& Y. X& I) f8 R& m, p# f8 I; R  G+ N7 _+ T  T$ C& P4 r
Firefox 4.0.1 – Windows
) A- l6 j! N, D! d& P( ?User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
& l9 {8 p/ J5 m( i! k& ~1 N- e7 U3 P1 \. r& I
Opera 11.11 – MAC
2 X' k  {( z$ PUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.110 E" f3 @. r- G4 J- }% W6 N: K. E* x4 ?
$ d' l6 }0 t! x5 |6 r' Q% J
Opera 11.11 – Windows8 ?. C6 |* ?/ q
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.112 U5 Z  L! }8 ]: q

( t! L- L7 e/ y0 UChrome 17.0 – MAC5 y9 M  h+ m/ w" G9 M
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( d, @" ~8 p" B" T3 n
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)2 M5 P* y+ u0 m0 f+ H  |: J. C4 F

+ R; Y$ m$ e# p  r* d- L8 L( |2 LTT6 c) x1 P1 M4 o
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
9 B  s4 f1 d/ X, B7 t# c  L9 m9 U! v# x) p5 b
The World 2.x( T" n+ |9 F) N! R$ U0 c2 Y
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
, z8 a& p% \* Z# N# i2 B2 e* b& v4 W4 G# X3 u
The World 3.x5 j+ W1 d3 j- i8 D
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
8 {& V0 W) j/ S) T4 A0 t) t$ d7 o. n1 h! |$ ~& _
搜狗浏览器 1.x0 b! j' l* d0 g8 i7 ^  K8 v$ ^
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)
) l; \' e! ?7 f5 l3 C. Y# Y2 [* G( }2 i$ \" u. r  S2 u
360SE
# g. m5 G1 i0 u& b4 G+ SUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)
3 r$ Y5 E) p+ H1 B+ g
3 u6 ?* d+ g3 ~8 P3 t1 N7 zAvant
% H$ G6 V; T; z% w# rUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
: B! R/ F; X; \+ |
: v9 z! y! t! \& Z" yGreen Browser
' `  j, \) i8 s* xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
( C/ g- H- R9 ]2 b/ |3 ?1 sUser-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* f3 ^0 g. ^: @! `

# b9 \1 K+ A7 D5 Csafari iOS 4.33 – iPod Touch
5 y1 T* l4 `. @9 {2 F3 gUser-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
- W1 U  T6 K- Y* A' x/ P4 i8 k2 n1 I1 l9 O8 E
safari iOS 4.33 – iPad
; C6 O2 b/ v9 \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
9 Z. \* \* G) _. o3 v
) X9 r' ]7 ]# t9 u0 X- [3 cAndroid N1
& G- y. [- D3 jUser-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
1 W: V  G# S0 @( Y; C2 \0 m# x
Android QQ For android
* x$ w; I4 e7 B+ cUser-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
$ F2 [2 B& R4 Y5 t' F2 _; R- k+ {4 o
Android Opera Mobile
+ V  _6 Y" p! t: {2 gUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
2 G/ C6 P- y0 M8 m6 y1 S3 n  h5 x, p* K) \9 Q5 N9 w: o
Android Pad Moto Xoom
8 d& p& D% c$ j/ X# b; d" M" |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& c2 W+ _5 b) z

. @& @5 m- ~- J* k$ F$ FBlackBerry! u7 n8 F' P" N. v- c& o' z' G
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+ ~, X2 W# a. F9 X. j. {/ \9 O2 t6 U
WebOS HP Touchpad5 D( ]# ]3 }$ Q8 t
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.04 Y+ v0 M' P' t' a6 r% P
. e+ a4 z$ P9 m) A5 s: B$ p; ~% l3 s
Nokia N97
4 U% ~; k+ S; s' }' yUser-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.181243 a- x$ t+ x* B7 o! O

7 W, D0 |' y6 }& ~( t3 S/ G6 NWindows Phone Mango
% ^" N. K. }7 f; w* |+ B$ z5 nUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)( d' N! f% l, X( U4 e8 A+ K
7 Q1 U5 r& ]; \9 _1 n1 Y+ c
UC标准% u& b' M/ R3 T; M
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999
1 r% E9 o3 B) b0 P( }! F& Y7 _2 b
) Y7 q1 h/ W, J4 x1 E% n1 L; uUCOpenwave
# @% R$ ~0 g- D% q+ J8 oUser-Agent: Openwave/ UCWEB7.0.2.37/28/999; ~5 Y4 @1 B* l* d" H: A( s8 j

% I, V. A3 T0 g3 ]7 X6 YUC Opera
, }1 a7 D7 o; F; Q6 |# hUser-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
互联网安全