Home >Backend Development >PHP Tutorial >PHP gets device type instance code
How to get the device type in php? This article mainly shares with you the example code of obtaining device type in PHP, hoping to help you.
<?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"; } ?>
Related recommendations:
Get the device type of user login system + version number
PHP implements automatic jump according to the device type Page method
PHP method to automatically jump to the corresponding page according to device type_PHP
The above is the detailed content of PHP gets device type instance code. For more information, please follow other related articles on the PHP Chinese website!