Home  >  Article  >  Backend Development  >  Three ways to determine whether a mobile phone is IOS or Android using PHP

Three ways to determine whether a mobile phone is IOS or Android using PHP

墨辰丷
墨辰丷Original
2018-06-05 17:15:483336browse

This article mainly introduces three methods of PHP to determine whether a mobile phone is IOS or Android. Friends who are interested can refer to it. I hope it will be helpful to everyone.

Example 1: Mainly uses HTTP_USER_AGENT, which means it is used to check what operating system (including version number) browser (including version number) the visitor browsing the page is using. number) and the user's personal preference code.

The monitoring code is as follows:

function get_device_type()
{
 //全部变成小写字母
 $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
 $type = 'other';
 //分别进行判断
 if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))
{
 $type = 'ios';
 } 
 
 if(strpos($agent, 'android'))
{
 $type = 'android';
 }
 return $type;
}

By calling the Objective-C function, you can get the type of mobile phone.

Example 2: All you need is one judgment

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

Example 3: This example may be a little off topic but I will share it with everyone

function get_device_type()
{
 //全部变成小写字母
 $agent = strtolower($_SERVER[&#39;HTTP_USER_AGENT&#39;]);
 $type =&#39;other&#39;;
 //分别进行判断
 if(strpos($agent,&#39;iphone&#39;) || strpos($agent,&#39;ipad&#39;))
{
 $type =&#39;ios&#39;;
 }
 
 if(strpos($agent,&#39;android&#39;))
{
 $type =&#39;android&#39;;
 }
 return$type;
}

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php WeChat automatically obtains the delivery address api usage example detailed explanation

PHP determines whether the user has logged in instance analysis

php method to implement WeChat public account custom sharing content

The above is the detailed content of Three ways to determine whether a mobile phone is IOS or Android using PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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