Home > Backend Development > PHP Tutorial > Code to detect Android devices via JavaScript or PHP_PHP Tutorial

Code to detect Android devices via JavaScript or PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:31:06
Original
983 people have browsed it

With the return of Steve Jobs and the release of iPad 2, it seems that the topic of mobile development is becoming more and more popular. Here are some detection methods that can be used on Android, the biggest competitor of iOS.

JavaScript Judgment Method

Searching for Android words in the user agent string is the easiest way:

Copy code The code is as follows:

if(navigator.userAgent.match(/Android/i)) {
// Do something!
// Redirect to Android-site?
window.location = 'http://android.davidwalsh.name';
}

PHP judgment method

Similarly, we can use the strstr method to search for user in PHP Whether there is Android in the agent:
Copy code The code is as follows:

if(strstr($_SERVER['HTTP_USER_AGENT'], 'Android')) {
header('Location: http://android.davidwalsh.name');
exit();
}

In addition, you can pass .htaccess to determine

We can use .htaccess to determine and respond to Android devices!
Copy code The code is as follows:

RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.davidwalsh.name [R=301]

This way You’ve got all three ways to detect Android devices.

Original link: http://article.yeeyan.org/view/56089/176760

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323077.htmlTechArticleWith the return of Steve Jobs and the release of iPad2, it seems that the topic of mobile development is becoming more and more popular. Here are some detection methods that can be used on the Android system, the biggest competitor of iOS...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template