Js and php determine whether it is an android device

Source: Internet
Author: User

The JavaScript judgment method is to directly search the Android string in the user agent string of the client:

If (navigator. userAgent. match (/Android/I )){
Alert ('Is Android! ');
} Else {
Alert ('is Not Android! ');
}

The PHP method can also be used to search for Android keywords in the user agent:

If (strstr ($ _ SERVER ['http _ USER_AGENT '], 'Android ')){
Echo 'Is Android! ';
} Else {
Echo 'Is Not Android! ';
}

Next, let's talk about

Php Tutorial: determine the browser type based on HTTP_USER_AGENT

Function browsers (){
Global $ HTTP_USER_AGENT;
If (isset ($ HTTP_USER_AGENT )){
$ SAgent = $ HTTP_USER_AGENT;
} Else {
$ SAgent = $ _ SERVER ['http _ USER_AGENT '];
   }
If (strpos ($ sAgent, 'msi ')! ==False & strpos ($ sAgent, 'Mac') ===false & strpos ($ sAgent, 'Opera ') === false ){
$ IVersion = (float) substr ($ sAgent, strpos ($ sAgent, 'msie ') + 5, 3 );
Return ($ iVersion> = 5.5 );
} Else if (strpos ($ sAgent, 'Gecko /')! = False ){
$ IVersion = (int) substr ($ sAgent, strpos ($ sAgent, 'Gecko/') + 6, 8 );
Return ($ iVersion> = 20030210 );
} Else {
Return false;
   }
  }

For more details, see: http://www.111cn.net/phper/18/e6800bfcf8106373d02b9c7d8af118dc.htm

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.