Js and php determine whether it is an android device

Source: Internet
Author: User
Tags php tutorial

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.