$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.         ?>
复制代码
- {# S# L1 ]# }# x3 Y( b; I


9 L1 J& B% w' s7 Y! H/ r! p+ x

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.         %>
复制代码
6 ~5 o  P! w2 U6 c$ W* N

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.         }
复制代码
& H9 u- z# ^" t/ _& Z$ w

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

+ ~  E5 r7 B& _3 H

" p+ r& a+ ~  d* J# z1 Y

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
9 ]% `& g7 Y$ u3 LUser-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! g2 y( y+ S3 B8 w

* ?* f: n  u0 m1 {) m& k* Osafari 5.1 – Windows' k( U' i7 X) n5 z* u5 r1 ?, f* u  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.507 K0 h1 D. K% b- G. P0 T  u9 ]

" W/ y+ G0 ~8 A/ g2 i1 z! ^IE 9.0
  @9 G+ H& q$ d: }; X2 D5 n$ ]User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
' p! Y  j+ c2 w! }! J+ y" E3 z9 o( a
IE 8.0
: Y+ V! W/ }6 M$ E) AUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
  G* N! F/ }# g7 C9 e. K# L/ I2 V/ T' w, ~( @
IE 7.06 Z2 s& k( x5 m5 a$ u, ~  u
User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)$ p# ^8 R- Y! S6 n8 X
2 Z4 f5 t( y& B7 e- F
IE 6.0
5 X# ^# |/ N5 [: u. W! d, d; \* J* EUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
2 E$ C6 m- w4 d! l8 [- W- k
- z' i$ h( k+ w: f/ ~Firefox 4.0.1 – MAC
8 v& a3 g# H* bUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
2 d- \& D! Q& x6 b3 j0 V" q' a) z) r) f. c) h4 s
Firefox 4.0.1 – Windows1 K9 ^/ F% Z2 C' T* O9 F5 j7 I7 @
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
" C3 `0 r( I: w8 u2 q
$ ^3 T" T4 O: b6 ]0 \6 S& U6 ]% oOpera 11.11 – MAC8 a3 b$ y: i0 ]8 Z$ n( ~' ~
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
% W& l( I5 Y* }$ {4 s  c% n; Z- C7 i6 c# {9 K1 K
Opera 11.11 – Windows
9 J9 Z% I5 i1 w7 W" J  {) oUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
6 V8 F  ?! [8 |  s, Z( H; c; M2 a6 s* O; J6 F1 Q2 q) [
Chrome 17.0 – MAC6 Q2 z9 d0 ]1 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、国产浏览器

Maxthon2 o1 J" @; I* Y$ `( \! \
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)
% m( W  |0 x/ N) Z/ f# j# M) @3 T- d# T8 Q+ y" P4 g3 K
TT& ?4 C& j, b; P' u# E( F
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)( M2 T& e8 l6 h, U! r" H- o5 N

6 V* _. c) a0 @) |2 ?The World 2.x' B# ]- [+ G5 k: U+ y
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)0 ~+ k$ x& g, [7 ^& b" y6 y
$ g5 r; Y5 x  Z; a9 P: `" ^
The World 3.x3 k  G" h! [4 I) L' p) u& a7 F
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
" ?: I& e0 S+ U8 c- n: J& K5 h' X, |$ T$ s1 s/ z
搜狗浏览器 1.x3 i& a& L# ]0 E; p- K" i
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)
0 ~9 P5 N* \$ k$ w/ h, I* f% C3 p: J0 y/ `
360SE
( b; f! V2 U/ c7 V$ X# l2 Y: U" r3 iUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)0 n7 t. x$ R/ h$ z
/ J3 N: N/ \4 `' Z4 Z
Avant
9 R- w, D& e7 p' z" U4 n+ C% ~1 xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)0 Y7 ^7 y2 J' y+ O9 n" A
, y/ a$ `- r. R
Green Browser
, k, M- X8 o- i9 mUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
7 A; F4 J1 U: M1 eUser-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
3 V% J% N$ P0 r1 |0 y1 }4 f& E* X. k; Z
safari iOS 4.33 – iPod Touch
0 n  g8 D' I$ n4 y* j0 m% c' KUser-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
! g0 c6 k5 y/ R8 ]# S2 R9 l7 a& t" u5 w0 l: H; Q
safari iOS 4.33 – iPad
- M2 s5 x; g$ a: u, ZUser-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
- |8 W& G+ r5 w
: T( j1 `$ }8 d. v1 q! uAndroid N1
  E& i7 U* ~# p7 P4 e& AUser-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.12 l( o: F5 @  l# ]% t

" h6 J. g5 w; z9 kAndroid QQ For android
; }4 k. R$ V* f1 B8 L! i3 j6 B& LUser-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
% j# y6 e5 x, N# u0 h; [
: V  Z7 t6 c% O; @1 }; f- wAndroid Opera Mobile$ J6 p4 n: \+ D
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10
& y$ L1 D9 u' L% {7 `8 z. h8 i! N5 o1 K; F9 V. ]8 a
Android Pad Moto Xoom
1 R5 z* G+ |1 [" z# P8 k( X3 iUser-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.136 @4 N4 m/ P. F$ R( s0 L5 |# S9 k1 p

8 y! T* i* @7 FBlackBerry5 Q+ j% ?% K4 w/ |/ i
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+
+ H4 b% O8 g6 i1 D# {
. y! n2 c0 V/ h  ZWebOS HP Touchpad! v8 S; T4 P1 B$ 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
& P% Q+ z7 E0 D8 ]/ U6 R" W" N& _
# G: [* s3 ^5 Q+ q4 K$ `0 k  t5 wNokia N975 H' }/ t4 k+ Z, A: D
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
0 ^. [. A* i' q; w3 ?2 m
4 _6 p9 H' F5 X8 o, T7 eWindows Phone Mango" }. `( r* D; y) a" ~: {. h6 p; d
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
1 U/ c: a* d/ \! r$ d; ~# e; Q+ ^/ k3 G
UC标准2 W2 J  O' O2 J% P
User-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9997 h; v7 k% z" Z- ?. L! A
0 h; }' M- |! l$ ^0 {
UCOpenwave
( k& ?' ?8 C! F9 U7 s+ d6 ]) ~User-Agent: Openwave/ UCWEB7.0.2.37/28/999
% T! M) S7 t' z3 {
, r, E: y7 D& qUC Opera8 K) _" T2 Y7 G6 l: A. q
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
互联网安全