Home > Article > Backend Development > PHP determines whether it is an iPad
The example in this article describes how PHP simply determines iPhone, iPad, Android and PC devices. Share it with everyone for your reference. The details are as follows:
Because of work needs, we need to know what it is like. A user has visited my website. What is it now? There are many types of mobile devices. Let’s take a look at an example of PHP judging iPhone, iPad, Android, and PC devices compiled by the editor. (Recommended learning: PHP Video Tutorial)
I set the device using Windows system as PC. After all, the blog is for Chinese users, and most home devices still use Windows system.The principle is to determine the USER AGENT submitted by the browser. The code is as follows:
<?php //获取USER AGENT $agent = strtolower($_SERVER['HTTP_USER_AGENT']); //分析数据 $is_pc = (strpos($agent, 'windows nt')) ? true : false; $is_iphone = (strpos($agent, 'iphone')) ? true : false; $is_ipad = (strpos($agent, 'ipad')) ? true : false; $is_android = (strpos($agent, 'android')) ? true : false; //输出数据 if($is_pc){ echo "这是PC"; } if($is_iphone){ echo "这是iPhone"; } if($is_ipad){ echo "这是iPad"; } if($is_android){ echo "这是Android"; } ?>
The above is the detailed content of PHP determines whether it is an iPad. For more information, please follow other related articles on the PHP Chinese website!