Home >Backend Development >PHP Tutorial >Three ways to determine whether a mobile phone is IOS or Android using PHP
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['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 little off topic but I will share it with everyone
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; }
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!