Use JavaScript or PHP to detect the code of the Android device _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Use JavaScript or PHP to detect the code of the Android device. With the return of Steve Jobs and the release of iPad2, it seems that mobile development is becoming increasingly popular. Here we will list some detection methods that can be used in the Android system, the biggest competitor of iOS, with the return of Steve Jobs and the release of iPad2, it seems that mobile development is becoming increasingly popular. This section describes how to detect the Android system, the biggest competitor to iOS.

JavaScript judgment method

Searching for Android words in the user agent string is the most convenient method:

The code is as follows:


If (navigator. userAgent. match (/Android/I )){
// Do something!
// Redirect to Android-site?
Window. location = 'http: // android. Davy. name ';
}


PHP judgment method

Similarly, we can use the strstr method in PHP to search for Android in the user agent:

The code is as follows:


If (strstr ($ _ SERVER ['http _ USER_AGENT '], 'Android ')){
Header ('Location: http://android.davidwalsh.name ');
Exit ();
}


In addition, you can use. htaccess to determine

We can use. htaccess to determine and respond to Android devices!

The code is as follows:


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


In this way, you have mastered the detection methods of all three Android devices.

Link: http://article.yeeyan.org/view/56089/176760

Bytes. Here we will list some methods to detect the Android system, the biggest competitor to iOS...

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.