PHP three ways to determine whether a phone is iOS or Android

Source: Internet
Author: User
This article mainly introduces PHP to determine whether the mobile phone is iOS or Android three methods, interested in a friend's reference, I hope to be helpful to everyone.

Example 1: The main purpose is to use the http_user_agent, which means to check the browsing page of the visitors using what operating system (including version number) browser (including version number) and user preferences of the code.

The monitoring code is as follows:

function Get_device_type () {//all becomes lowercase $agent = strtolower ($_server[' http_user_agent ')), $type = ' other '; Strpos ($agent, ' iphone ') | | Strpos ($agent, ' ipad ') {$type = ' iOS ';}   if (Strpos ($agent, ' Android ')) {$type = ' Android ';} return $type;}

By calling Objective-c This function, you can get the type of the phone.

Example 2: just need a judgment.

<?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 ';}? >

Example 3: This example may be a bit tricky but it's shared with everyone.

function Get_device_type () {//all becomes lowercase $agent = strtolower ($_server[' http_user_agent ')), $type = ' other '; Strpos ($agent, ' iphone ') | | Strpos ($agent, ' ipad ') {$type = ' iOS ';}  if (Strpos ($agent, ' Android ')) {$type = ' Android ';} Return$type;}

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.