PHP determines whether the mobile phone is IOS or Android

Source: Internet
Author: User
This article mainly introduces three examples for PHP to determine whether a mobile phone is IOS or Android, interested friends can refer to this article to introduce three small instances in PHP for judging whether the mobile phone is IOS or Android. to determine whether the user's mobile phone is Android or ios, I searched the relevant materials and shared the final results with you.

Instance 1:HTTP_USER_AGENT is used to check the operating system (including the version) browser (including the version number) and user preference code used by page visitors.
The monitoring code is as follows:

Function get_device_type () {// All are lowercase letters $ agent = strtolower ($ _ SERVER ['http _ USER_AGENT ']); $ type = 'other '; // Determine if (strpos ($ agent, 'iPhone ') | strpos ($ agent, 'iPad') {$ type = 'iOS ';} if (strpos ($ agent, 'Android') {$ type = 'Android';} return $ type ;}

By callingObjective-CThis function can obtain the mobile phone type.

Instance 2:Only one judgment is needed.

<?phpif(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){ echo 'systerm is IOS';}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){ echo 'systerm is Android';}else{ echo 'systerm is other';}?>

Instance 3:This instance may have some questions but I will share them with you.

Function get_device_type () {// All are lowercase letters $ agent = strtolower ($ _ SERVER ['http _ USER_AGENT ']); $ type = 'other '; // Determine if (strpos ($ agent, 'iPhone ') | strpos ($ agent, 'iPad') {$ type = 'iOS ';} if (strpos ($ agent, 'Android') {$ type = 'Android';} return $ type ;}

Finally, "Buy 3 get one free" will share with you a small instance that has little to do with this topic:

Php checks whether the page is open

$ User_agent = $ _ SERVER ['http _ USER_AGENT ']; if (strpos ($ user_agent, 'micromessenger') === false) {// you are not allowed to browse echo "HTTP/1.1 401 Unauthorized";} else {// The browser allows access to echo "MicroMessenger"; // you can obtain the preg_match ('/. *? (MicroMessenger \/([0-9.] +) \ s */', $ user_agent, $ matches); echo'
Version: '. $ matches [2];}

The above is the three-step PHP code for judging whether the mobile phone is IOS or Android. I hope you will like it and make persistent efforts to provide more practical articles for everyone.

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.