Home >Backend Development >PHP Tutorial >PHP determines whether the client is PC or mobile phone
The code function of this article is to use PHP to determine whether the client is a PC or a mobile phone. It has certain reference value and interested friends can learn about it.
function is_mobile(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $is_pc = (strpos($agent, 'windows nt')) ? true : false; $is_mac = (strpos($agent, 'mac os')) ? true : false; $is_iphone = (strpos($agent, 'iphone')) ? true : false; $is_android = (strpos($agent, 'android')) ? true : false; $is_ipad = (strpos($agent, 'ipad')) ? true : false; if($is_pc){ return false; } if($is_mac){ return true; } if($is_iphone){ return true; } if($is_android){ return true; } if($is_ipad){ return true; } }
Related tutorials: PHP video tutorial
The above is the detailed content of PHP determines whether the client is PC or mobile phone. For more information, please follow other related articles on the PHP Chinese website!