$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.         ?>
复制代码
* y0 b+ H4 N5 N+ x$ {0 W3 m1 W

5 G2 i  a& N  R, `5 V

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

- m* ?/ }, W) x: g( l) D' l. @

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

1 i6 H9 z8 [4 q

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


- j; F& |! [& n, r# n8 V' u# c6 ?; J& w

浏览器UA大全

1、主要浏览器

safari 5.1 – MAC2 w# R' e/ H& Y3 i$ X
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
4 h/ C6 ?7 Q+ d! e2 C4 G1 Z& P: ]' h
' B6 D' Y. B2 g7 ~4 Qsafari 5.1 – Windows; e* @' J4 n) J6 ^, n
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/ Z. q, _% ^3 C6 N3 B1 w5 t) t
9 E3 w7 y$ I# G
IE 9.0- d8 q2 }( |* `
User-Agent:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;
# I: m4 R, \& _8 Y. J  I' H# o+ P# H, i$ [+ E1 w: g$ z- ?& S
IE 8.0
: i& H8 E' L  L. CUser-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0): O. A6 ^/ E' {4 _
' W, v& s- u: y+ s- F* m8 j1 F
IE 7.0
4 [+ J$ p) G0 u8 tUser-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)/ y7 m$ R' P9 b! u

( F/ Z4 g8 `. p9 T; rIE 6.0, q2 z4 n# P8 d5 B- S3 \. Y! H
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
/ }" N: K% z2 e2 u6 K
9 T6 u8 c  b# _& D5 i; lFirefox 4.0.1 – MAC
/ U8 b$ _5 j! c! T9 B- N% J- {User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1( E' K+ Q! q1 Q# D0 h
9 Q$ U4 J5 p; d/ G* }3 ?& W
Firefox 4.0.1 – Windows
' ]+ s5 Z- T+ y& b2 ZUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.12 B8 w# A5 f& s- R: D2 u4 K
' j5 B4 W% Z7 ?  M+ ^9 s
Opera 11.11 – MAC! x; W$ O! v$ l  a# u6 V
User-Agent:Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11. ]3 R0 o4 F6 j  D! U  n; M: q7 W

" e; L3 E- Q1 R7 @& N, iOpera 11.11 – Windows5 u; ^" w1 v0 q, X# p& S
User-Agent:Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.118 f2 G& O) Y; S/ {" R' D# w

( i- [1 h9 ^% VChrome 17.0 – MAC: Y/ E+ C3 U2 j/ F
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) t. M0 d8 M1 ~; C. S% S+ L5 t6 W$ j
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0). s: c8 o- h" X) }. ^0 F" N

% A+ h- j: J7 a, j: x! t; ATT
5 g6 Z' g* e8 d0 c5 FUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)
4 N$ B+ A* X1 [  R) N* Q7 V
- I3 L# [8 X* l5 ?! C* t" aThe World 2.x5 j) _6 q% c/ r# @- |- {
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)6 }7 W) a/ D6 `" T9 m

2 T" M5 |/ }( [7 Q; M1 xThe World 3.x4 n* D0 W9 b! Z7 r) B! U3 @, c
User-Agent:?Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)
( p) \1 Q3 o" O& m( r; f  M8 C- h+ c8 l. |, D
搜狗浏览器 1.x0 k! d; ?# {& m) w, Z" M! x
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 N) B& `% W8 i+ ?, B$ p5 G! [* V* S+ U4 r
360SE, ?  s' }6 S  T: {3 R& k3 D
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)4 n" B# E3 q. v( G- q2 t1 N

3 s9 `- c4 N% `9 Q3 eAvant
5 a4 H1 d3 d6 K5 E* |User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
& @$ ~* m1 K: w, u1 E
1 P  u# M" Q  _6 k. `& l  CGreen Browser
( Y& A' c2 e2 L4 v0 AUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3、移动设备端

safari iOS 4.33 – iPhone
' I5 w3 n  G7 n4 x' O' k7 DUser-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
( H  M% Y" s0 P: n
8 @. v* r7 W1 X4 ~5 `: b% [: Osafari iOS 4.33 – iPod Touch4 w5 D7 ]' c5 y
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
- K) l9 a( c# o, x% Z2 Z. c' q" W0 \5 s2 ~; c% e
safari iOS 4.33 – iPad
, P( @( R6 t( }) X- o" FUser-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( R( F, m8 c' b( `
& c. N" P3 G3 [: r3 I2 c
Android N14 ]7 }( d" F* ?0 ~  O! e0 r
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) N3 Z+ V5 E) Z6 {% B) f0 Q2 W
, ?/ \7 g7 i( e. B/ Y  T+ u
Android QQ For android( Y; A* O( ~/ h! {
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
9 E1 n8 x7 s7 ^$ j0 F0 B+ g9 G0 g( L' r+ t' l
Android Opera Mobile
/ \0 x7 z# Y6 [) W, B, vUser-Agent: Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10  T& s- s5 P& }' K6 @- j+ p

! B; o% f3 v* }6 lAndroid Pad Moto Xoom
) r* `/ T0 ~( XUser-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.134 S9 x6 F: x! Z3 p! q
6 B) \) V/ L7 d
BlackBerry
- p3 h% T  W* f1 [0 pUser-Agent: Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+1 T0 g) p$ C+ f  J$ |" R

4 A- S9 ~# i% `0 ^! C3 |) jWebOS HP Touchpad5 ]5 b- b2 g0 X3 y
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# U8 T  k3 F/ L4 U9 \& Q
, I2 R! V2 X- Z6 R& N
Nokia N97
. c' |8 ?# ~$ KUser-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 e& `( M$ O; E( h  g  B7 W4 @, {2 o3 B2 ~; E' u, c) W
Windows Phone Mango
; S+ e6 a: ]# T  h5 [User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)* e4 x% p; P& S" }: V

- N, X  w& W8 k# N0 B3 jUC标准
& F: x$ V0 x7 dUser-Agent: NOKIA5700/ UCWEB7.0.2.37/28/9991 f7 i# j$ o- b0 j& ~
8 @' z1 |7 N' I0 s2 n
UCOpenwave
, E5 I, D% j1 o6 t3 d( u! I$ tUser-Agent: Openwave/ UCWEB7.0.2.37/28/999
) k, Z5 R4 \5 e( V
' s# N/ o  Y+ ^& cUC Opera
; Y& z5 f- }& z5 {# HUser-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
互联网安全