With the return of Steve Jobs, IPad2 's release, it seems that the mobile side of the development of the topic more and more hot. Here are some of the top competitors in iOS-android (Android) system detection method.
JavaScript Judgment method
Searching for the Android word in the user agent string is the most provincial way:
Copy the Code code as follows:
if (Navigator.userAgent.match (/android/i)) {
Do something!
Redirect to Android-site?
window.location = ' http://android.davidwalsh.name ';
}
PHP Judgment method
Again, we can use the Strstr method in PHP to search for Android in the user agent:
Copy the Code code as follows:
if (strstr ($_server[' http_user_agent '), ' Android ') {
Header (' Location:http://android.davidwalsh.name ');
Exit ();
}
In addition, it can be judged by. htaccess.
We can use. htaccess to judge and respond to Android devices!
Copy the Code code as follows:
Rewritecond%{http_user_agent} ^.*android.*$
Rewriterule ^ (. *) $ http://android.davidwalsh.name [r=301]
This allows you to master all three types of Android device detection methods.
Original link: http://article.yeeyan.org/view/56089/176760
The above describes PHP and JavaScript through JavaScript or PHP to detect Android device code, including PHP and JavaScript content, I hope to be interested in PHP tutorial friends helpful.