Php/asp/asp.net to judge the Baidu Mobile and the implementation of the PC Spider code _ related skills

Source: Internet
Author: User
Tags servervariables

As mobile traffic is increasing, we statistics website traffic time, need to move and PC traffic separate, and encounter Baidu Spider time, in order to better and more detailed statistics, also need to Baidu Spider mobile end and PC side separately to statistics, this to the website analysis has very important significance. This article provides a judge Baidu Mobile Spider and Baidu pc spider source code, has PHP, ASP, asp.net three versions.

PHP version

 <?php
    $ua =$_server[' http_user_agent '];
    $ua =strtolower ($ua);
    if ($ua!= "" && Strpos ($ua, "Baiduspider")) {
      if (Strpos ($ua, "Android") | | strpos ($UA, "mobile")) {
        echo is Baidu Mobile UA ";
      } Else{
        echo "is Baidu Pcua";
      }
    else{
       echo "is not Baiduspider UA";
    >

This code is relatively simple, here for you to see this article http://www.jb51.net/article/72211.htm.

ASP version

<%
    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 "is Baidu Mobile ua"
      Else
        Response.Write "is Baidu pc UA" End
      if
    else
      Response.Write " Not Baiduspiderua "End
    if
    %>

Continue to recommend an ASP for you to determine whether the search engine code:

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
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 ("is the Baidu move UA");
      }
      else{
        Response. Write ("is Baidu pc UA");
      }
    else{
      Response. Write ("not Baiduspiderua");
    }
String agent = system.web.httpcontext.current.request.servervariables["Http_user_agent"];
  if (Agent = = null)
  {
  Response.Write ("other");
  }
  else
  {
  Response.Write (agent);
  }

The above demo is through UA to determine whether visitors are baiduspider, is a more common method.

Browser UA Encyclopedia

1. Main browser

Safari 5.1–mac
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

Safari 5.1–windows
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

IE 9.0
user-agent:mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; trident/5.0;

IE 8.0
user-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; trident/4.0)

IE 7.0
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)

IE 6.0
user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Firefox 4.0.1–mac
user-agent:mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) gecko/20100101 firefox/4.0.1

Firefox 4.0.1–windows
user-agent:mozilla/5.0 (Windows NT 6.1; rv:2.0.1) gecko/20100101 firefox/4.0.1

Opera 11.11–mac
user-agent:opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U EN) presto/2.8.131 version/11.11

Opera 11.11–windows
user-agent:opera/9.80 (Windows NT 6.1; U EN) presto/2.8.131 version/11.11

Chrome 17.0–mac
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. Domestic browser

Maxthon
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)

Tt
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Tencenttraveler 4.0)

The World 2.x
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

The World 3.x
User-agent:? mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The world)

Sogou Browser 1.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)

360SE
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)

Avant
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)

Green Browser
user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

3. Mobile device End

Safari IOS 4.33–iphone
user-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

Safari IOS 4.33–ipod Touch
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

Safari IOS 4.33–ipad
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

Android N1
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

Android QQ for Android
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

Android Opera Mobile
user-agent:opera/9.80 (Android 2.3.4; Linux; Opera mobi/build-1107180945; U EN-GB) presto/2.8.149 version/11.10

Android Pad Moto Xoom
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

BlackBerry
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+

WebOS HP Touchpad
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

Nokia N97
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

Windows Phone Mango
user-agent:mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; trident/5.0; iemobile/9.0; HTC; Titan)

UC Standard
user-agent:nokia5700/ucweb7.0.2.37/28/999

Ucopenwave
user-agent:openwave/ucweb7.0.2.37/28/999

UC Opera
user-agent:mozilla/4.0 (compatible; MSIE 6.0; ) opera/ucweb7.0.2.37/28/999

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.