php/asp/asp.netでは、Baiduの移動とPC蜘蛛の実現コードを判断します。
モバイルの流量が日増しに増えているため、私達はウェブサイトの流量を統計する時、モバイルとPCの流量を分離しなければならなくて、百度のクモに出会う時、もっと細い統計のため、百度のクモのモバイル端末とPC端末をそれぞれ統計しにくる必要があって、これはウェブサイトの分析に対してとても重要な意義を持っています。本文はBaiduの移動蜘蛛とBaiduのPC蜘蛛のソースコードを提供します。php、asp、asp.netの3つのバージョンがあります。
php版
asp版
ブラウザUA大全書
1、主要ブラウザ
safari 5.1 C MAC
User-Agent:Mozila/5.0(Macinth;U;Intel Mac OS X 10_6_8;en-us)Apple WebKit/534.50(KHTML、like Gecko)Version/5.1 Safari/534.50
safari 5.1 C Windows
User-Agent:Mozila/5.0(Windows;U;Windows NT 6.1en-us)Apple WebKit/534.50(KHTML、like Gecko)Version/5.1 Safari/534.50
IE 9.0
User-Agent:Mozila/5.0(comptible;MSIE 9.0Windows NT 6.1Trident/5.0;
IE 8.0
User-Agent:Mozila/4.0(comppatible;MSIE 8.0Windows NT 6.0Trident/4.0)
IE 7.0
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 6.0)
IE 6.0
User-Agent:Mozila/4.0(comppatible;MSIE 6.0Windows NT 5.1)
Firefox 4.0.1 C MAC
User-Agent:Mozila/5.0(Macinth;Intel Mac OS X 10.6;rv:2.0.1)Gecko/201001 Firefox/4.0.1
Firefox 4.0.1 C Windows
User-Agent:Mozila/5.0(Windows NT 6.1;rv:2.0.1)Gecko/201001 Firefox/4.0.1
Opera 11.11 C MAC
User-Agent:Opera/9.80(Macinth;Intel Mac OS X 10.6.8;U;en)Prestoo/2.8.131 Version/11.11
Opera 11.11 C Windows
User-Agent:Opera/9.80(Windows NT 6.1;U;en)Prestoo/2.8.131 Version/11.11
Chrome 17.0 C MAC
User-Agent:Mozila/5.0(Macinth;Intel Mac OS X 10_7_0)Apple WebKit/535.11(KHTML、like Gecko)Chrome/17.0.963.56 Safari/535.11
2、国産ブラウザ
Maxthon
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1Maxthon 2.0)
TT
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1TencentTraveler 4.0)
The World 2.x
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1)
The World 3.x
User-Agent:Mozilla/4.0(comppatible;MSIE 7.0Windows NT 5.1The World)
検索犬ブラウザ1.x
User-Agent:Mozilla/4.0(comppatible;MSIE 7.0Windows NT 5.1Trident/4.0SE 2.X MetaSr 1.0SE 2.X MetaSr 1.0NET CLR 2.5.0727SE 2.X MetaSr 1.0)
360 SE
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1360 SE)
Avant
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1Avant Browser)
Green Browser
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1)
3、モバイルデバイス端
safari iOS 4.33 C iPhone
User-Agent:Mozila/5.0(iPhone;U;CPU iPhone OS 4_3_3 like Mac OS Xen-us)Apple WebKit/533.17.9(KHTML、like Gecko)Verssion/5.0.2 Mobile/8 J 2 Safari/6533.18.5
safari iOS 4.33 C iPod touch
User-Agent:Mozila/5.0(iPod;U;CPU iPhone OS 4_3_3 like Mac OS Xen-us)Apple WebKit/533.17.9(KHTML、like Gecko)Verssion/5.0.2 Mobile/8 J 2 Safari/6533.18.5
safari iOS 4.33 C iPad
User-Agent:Mozila/5.0(iPad;U;CPU OS 4_3_3 like Mac OS Xen-us)Apple WebKit/533.17.9(KHTML、like Gecko)Verssion/5.0.2 Mobile/8 J 2 Safari/6533.18.5
Android N 1
User-Agent:Mozila/5.0(Linux;U;Android 2.3.7エプラスNexus One Build/FRF 91)Apple WebKit/533.1(KHTML、like Gecko)Verssion/4.0 Mobile Safari/533.1
Android QQ For android
User-Agent:MQBrowser/26 Mozar/5.0(Linux;U;Android 2.3.7zh-cnMB 200 Build/GRJ 22CyanogenMod-7)Apple WebKit/533.1(KHTML、like Gecko)Verssion/4.0 Mobile Safari/533.1
Android Opera Mobile
User-Agent:Opera/9.80(Android 2.3.4;LinuxOpera Mobi/build-1107180945;U;en-GB)Prestoo/2.8.149 Version/11.10
Android Pad Moto Xoom
User-Agent:Mozila/5.0(Linux;U;Android 3.0エプラスXoom Build/HRI 39)Apple WebKit/534.13(KHTML、like Gecko)Version/4.0 Safari/534.13
ブラックベリー
User-Agent:Mozila/5.0(BlackBerry;U;ブラックベリー9800en)Apple WebKit/534.1+(KHTML、like Gecko)Version/6.0.0.37 Mobile Safari/534.1+
WebOS HP Touchpad
User-Agent:Mozila/5.0(hp-tables;LinuxhpwOS/3..0;U;en-US)Apple WebKit/534.6(KHTML、like Gecko)wOSTBrowser/233.70 Safari/534.6 TouchPad/1.0
Nokia N 97
User-Agent:Mozila/5.0(Symbian OS/9.4;Series 60/5.0 NokiaN 97-1/20.019;Profile/MIDP-2.1 Configration/CLDC-1.1)Apple WebKit/525(KHTML,like Gecko)BrowserNG/7.1.18124
Windows Phone Mango
User-Agent:Mozila/5.0(comptible;MSIE 9.0Windows Phone OS 7.5;Trident/5.0;IEMobile/9.0HTC;Titan)
UC標準
User-Agent:NOKIA 5700/UCWEB 7.0.27/28/999
UCOpenwave
User-Agent:Openwave/UCWEB 7.0.27/28/999
UC Opera
User-Agent:Mozila/4.0(comppatible;MSIE 6.0Opera/UCWEB 7.0.27/28/999
php版
<?php
$ua=$_SERVER['HTTP_USER_AGENT'];
$ua=strtolower($ua);
if($ua!="" && strpos($ua,"baiduspider")){
if(strpos($ua,"android") || strpos($ua,"mobile")){
echo " UA";
}else{
echo " PCUA";
}
} else{
echo" baiduspider UA";
}
?>
このコードは簡単です。ここではこの文章を紹介します。asp版
<%
ua=Request.ServerVariables("HTTP_USER_AGENT")
ua=LCase(ua)
if ua<>"" and InStr(ua,"baiduspider")<>0 then
if InStr(ua,"android")<>0 or InStr(ua,"mobile")<>0 then
response.write " UA"
else
response.write" PC UA"
end if
else
response.write " baiduspiderUA"
end if
%>
引き続き、ASPで検索エンジンと判断されるコードを紹介します。
function isspider()
dim i,agent,searray
agent="agent:"&LCase(request.servervariables("http_user_agent"))
searray=array("googlebot","baiduspider","sogouspider","yahoo","Sosospider")
isspider= false
for i=0 to ubound(searray)
if (instr(agent,searray(i))>0) then isspider=true
next
end function
asp.net
string ua = Request.ServerVariables["HTTP_USER_AGENT"];
ua=ua.ToLower ();
if(ua != "" && ua.IndexOf("baiduspider") > -1){
if (ua.IndexOf("android") > -1 || ua.IndexOf("mobile") > -1)
{
Response .Write(" UA");
}
else{
Response .Write(" PC UA");
}
}
else{
Response .Write(" baiduspiderUA");
}
string agent = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
if (agent == null)
{
Response.Write("Other");
}
else
{
Response.Write(agent);
}
以上のdemoはuaを通じて訪問者がBaiduspiderかどうかを判断するのが一般的な方法です。ブラウザUA大全書
1、主要ブラウザ
safari 5.1 C MAC
User-Agent:Mozila/5.0(Macinth;U;Intel Mac OS X 10_6_8;en-us)Apple WebKit/534.50(KHTML、like Gecko)Version/5.1 Safari/534.50
safari 5.1 C Windows
User-Agent:Mozila/5.0(Windows;U;Windows NT 6.1en-us)Apple WebKit/534.50(KHTML、like Gecko)Version/5.1 Safari/534.50
IE 9.0
User-Agent:Mozila/5.0(comptible;MSIE 9.0Windows NT 6.1Trident/5.0;
IE 8.0
User-Agent:Mozila/4.0(comppatible;MSIE 8.0Windows NT 6.0Trident/4.0)
IE 7.0
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 6.0)
IE 6.0
User-Agent:Mozila/4.0(comppatible;MSIE 6.0Windows NT 5.1)
Firefox 4.0.1 C MAC
User-Agent:Mozila/5.0(Macinth;Intel Mac OS X 10.6;rv:2.0.1)Gecko/201001 Firefox/4.0.1
Firefox 4.0.1 C Windows
User-Agent:Mozila/5.0(Windows NT 6.1;rv:2.0.1)Gecko/201001 Firefox/4.0.1
Opera 11.11 C MAC
User-Agent:Opera/9.80(Macinth;Intel Mac OS X 10.6.8;U;en)Prestoo/2.8.131 Version/11.11
Opera 11.11 C Windows
User-Agent:Opera/9.80(Windows NT 6.1;U;en)Prestoo/2.8.131 Version/11.11
Chrome 17.0 C MAC
User-Agent:Mozila/5.0(Macinth;Intel Mac OS X 10_7_0)Apple WebKit/535.11(KHTML、like Gecko)Chrome/17.0.963.56 Safari/535.11
2、国産ブラウザ
Maxthon
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1Maxthon 2.0)
TT
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1TencentTraveler 4.0)
The World 2.x
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1)
The World 3.x
User-Agent:Mozilla/4.0(comppatible;MSIE 7.0Windows NT 5.1The World)
検索犬ブラウザ1.x
User-Agent:Mozilla/4.0(comppatible;MSIE 7.0Windows NT 5.1Trident/4.0SE 2.X MetaSr 1.0SE 2.X MetaSr 1.0NET CLR 2.5.0727SE 2.X MetaSr 1.0)
360 SE
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1360 SE)
Avant
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1Avant Browser)
Green Browser
User-Agent:Mozila/4.0(comppatible;MSIE 7.0Windows NT 5.1)
3、モバイルデバイス端
safari iOS 4.33 C iPhone
User-Agent:Mozila/5.0(iPhone;U;CPU iPhone OS 4_3_3 like Mac OS Xen-us)Apple WebKit/533.17.9(KHTML、like Gecko)Verssion/5.0.2 Mobile/8 J 2 Safari/6533.18.5
safari iOS 4.33 C iPod touch
User-Agent:Mozila/5.0(iPod;U;CPU iPhone OS 4_3_3 like Mac OS Xen-us)Apple WebKit/533.17.9(KHTML、like Gecko)Verssion/5.0.2 Mobile/8 J 2 Safari/6533.18.5
safari iOS 4.33 C iPad
User-Agent:Mozila/5.0(iPad;U;CPU OS 4_3_3 like Mac OS Xen-us)Apple WebKit/533.17.9(KHTML、like Gecko)Verssion/5.0.2 Mobile/8 J 2 Safari/6533.18.5
Android N 1
User-Agent:Mozila/5.0(Linux;U;Android 2.3.7エプラスNexus One Build/FRF 91)Apple WebKit/533.1(KHTML、like Gecko)Verssion/4.0 Mobile Safari/533.1
Android QQ For android
User-Agent:MQBrowser/26 Mozar/5.0(Linux;U;Android 2.3.7zh-cnMB 200 Build/GRJ 22CyanogenMod-7)Apple WebKit/533.1(KHTML、like Gecko)Verssion/4.0 Mobile Safari/533.1
Android Opera Mobile
User-Agent:Opera/9.80(Android 2.3.4;LinuxOpera Mobi/build-1107180945;U;en-GB)Prestoo/2.8.149 Version/11.10
Android Pad Moto Xoom
User-Agent:Mozila/5.0(Linux;U;Android 3.0エプラスXoom Build/HRI 39)Apple WebKit/534.13(KHTML、like Gecko)Version/4.0 Safari/534.13
ブラックベリー
User-Agent:Mozila/5.0(BlackBerry;U;ブラックベリー9800en)Apple WebKit/534.1+(KHTML、like Gecko)Version/6.0.0.37 Mobile Safari/534.1+
WebOS HP Touchpad
User-Agent:Mozila/5.0(hp-tables;LinuxhpwOS/3..0;U;en-US)Apple WebKit/534.6(KHTML、like Gecko)wOSTBrowser/233.70 Safari/534.6 TouchPad/1.0
Nokia N 97
User-Agent:Mozila/5.0(Symbian OS/9.4;Series 60/5.0 NokiaN 97-1/20.019;Profile/MIDP-2.1 Configration/CLDC-1.1)Apple WebKit/525(KHTML,like Gecko)BrowserNG/7.1.18124
Windows Phone Mango
User-Agent:Mozila/5.0(comptible;MSIE 9.0Windows Phone OS 7.5;Trident/5.0;IEMobile/9.0HTC;Titan)
UC標準
User-Agent:NOKIA 5700/UCWEB 7.0.27/28/999
UCOpenwave
User-Agent:Openwave/UCWEB 7.0.27/28/999
UC Opera
User-Agent:Mozila/4.0(comppatible;MSIE 6.0Opera/UCWEB 7.0.27/28/999