$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.         ?>
复制代码
6 j8 l! c; Y. e

1 T/ l, I) t( q% X" q. T* l4 @' ~) A

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

' D8 c: O( E8 Q$ [: H

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

% e0 X1 P1 @# g: ^* S, R

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

7 m% {* s& ]( N) J& h6 B7 P' _, \

2 N. n# [0 M: M  D% V' H

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC
- O% v& z  D$ a# q  O" z+ jUser-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
, I6 a: c  @; R; Y9 f, L/ Z9 N
) O, H3 N2 q, m* `0 y1 Osafari 5.1 – Windows
$ T+ f9 O1 W$ QUser-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50, }# \# s0 W% F8 _# e7 R

9 |$ b. k3 S: b( Q$ eIE 9.0
1 p3 F$ f/ e0 Q6 I) YUser-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
+ U8 U: `9 a) Y9 O# C3 f
7 w" a, C/ a4 M- r4 RIE 8.03 I# |0 Z5 E. `( l
User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
* z1 V; c% _" [. D% T5 M  Z* s: D4 b8 d' ], i" `6 }
IE 7.0
  x3 F3 j3 W# Z" sUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
; c+ n2 X5 j# ]% f! h1 e8 c* J0 [. A0 M  {: \) d8 H/ m
IE 6.0& o2 ^; `5 i7 p; j9 T" y  u
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
1 j* @9 r1 b# K/ p' x+ W
$ X6 S, f' e3 G+ X+ TFirefox 4.0.1 – MAC0 w1 g! y! R  e; e; _
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
# h& x+ s" E* p; q0 f& Y+ l4 I" }3 O% [- f5 `
Firefox 4.0.1 – Windows% v( y4 P( Z0 H- o3 I( f8 O
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
" O! x( }1 g4 X, s( V5 C& ?* R
! Z, R' P1 l/ A1 e0 fOpera 11.11 – MAC
- S3 B+ {$ |0 n  w, n2 L# fUser-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11
. a: p& {, z. V" M/ }9 \0 J- [
5 v! \$ }2 n/ E  XOpera 11.11 – Windows
0 i9 ?1 F3 _/ a* F; |9 t+ q6 O" zUser-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.117 N2 M; S5 u( m7 p# {
+ h3 H+ z6 V2 B  }2 P( ?- }
Chrome 17.0 – MAC! q3 v! |$ p  Q( h; v
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
+ k; o5 A8 K& M9 `. O. JUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)& J$ m  v$ {: r! o( {1 T8 F  e$ f
% i* g& n- o; N: R9 x, p
TT: x% \! y6 a5 U3 ^0 T/ F2 M
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)# d) M! n( U, i# B6 D5 i& j
+ x+ s# ^! Z9 M! l3 l5 k: g
The World 2.x
/ u. a: x* l7 o* z3 |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
" E3 u: ^# V, s, u: l1 Q2 H0 |( ~! L5 e5 m+ x/ O7 ?( G0 J5 x% D
The World 3.x9 @( ~+ O8 R7 S& v
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)# f' x8 E9 A; U, E) T1 r

8 @6 d0 |: }6 Y0 B8 v: a$ Y搜狗浏览器 1.x
$ F6 J  R- \1 p, R' YUser-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 h' M+ Y; _. A
! @2 o  k+ I7 a3 f: R3 D360SE
+ p# b; N+ w$ e6 q1 |6 |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)* e" @, g: }7 m, e" o  {
) e# A0 W& J! X8 v3 f& k- y
Avant
8 h8 u% ~+ n5 L% SUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)" V3 }! D9 A' U0 b, Y
* X- @3 f; a3 J$ i1 V
Green Browser
+ W" I3 {* V0 H: `8 d$ d9 xUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
4 Q0 ^) R7 @. N  W3 B' hUser-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
5 w. y$ Z0 {& d7 I- c/ c$ W
2 W/ l8 k: }/ {4 |safari iOS 4.33 – iPod Touch$ g9 H% d" l. K, m
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.5; R1 U( |7 D/ J1 u: q

# e- n* m. u7 H: ?" T# rsafari iOS 4.33 – iPad
. V3 O# m# J9 O$ `3 |9 YUser-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  ], E; M4 d& _+ p

' \" T! }* i( [+ HAndroid N1
" u, T* y0 r% S# A3 Q: h5 C6 X4 fUser-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
# b8 B2 Z7 h# i3 b
* ~" X- E( y* _4 }: L. o8 rAndroid QQ For android
( a4 ~* A9 G3 ?9 C0 |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.1
% w* l0 W# {3 M6 F& T: R, J; g* H& Q% r) E3 G" d! w
Android Opera Mobile* g& O/ N4 p( V
User-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10$ O3 l7 _: r& m* C) Y
# U% `* F& {: Z4 S! H
Android Pad Moto Xoom
# A6 O' D4 m4 ]: S1 s1 A# ^0 h9 |" rUser-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
, ]+ |0 C- e; ~0 z) T
# Y! l* R# V9 v3 N7 c$ |BlackBerry( r0 l1 x- C6 E9 ]  x
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+: h2 m% M8 w- L5 I

) X% _: c$ y, R; {WebOS HP Touchpad+ b) I3 g/ F: H
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& z4 \7 t$ }% T1 @9 v# a

3 v# l3 K& V( \/ H: o( r$ pNokia N97( F- l, f) Q9 X: ~- u& 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. a6 y( z2 _7 X- f- L

+ m2 O9 Q, n1 e& n9 v& CWindows Phone Mango
8 ^' E7 ~9 V7 s- ]) P9 WUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)
7 L5 ]# ~$ q1 P% t/ Q: P; e' }- ^& s# A; u7 k9 ~" T! {
UC标准
0 V0 l( w  P6 L) A6 A/ IUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/999) ?; r# V# Y7 w4 C( ~1 B

/ G# X5 v2 S8 S6 h2 eUCOpenwave
6 `# w2 T* `; x  n& CUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
3 y+ O- j  S  \1 P: ?
! Q7 V6 ^4 N' w+ ]- WUC Opera  L! i, k2 D" \- 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
互联网安全