Home > Backend Development > PHP Tutorial > PHP determines whether the client is PC or mobile phone

PHP determines whether the client is PC or mobile phone

little bottle
Release: 2023-04-06 12:34:02
forward
4932 people have browsed it

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;
        }
}
Copy after login

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!

Related labels:
php
source:51cto.com
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template