Home >Backend Development >PHP Tutorial >How to determine whether it is a mobile phone login through PHP method (code)

How to determine whether it is a mobile phone login through PHP method (code)

jacklove
jackloveOriginal
2018-06-08 14:03:063507browse

The judgment of mobile login is of great significance in PHP development. This article will introduce this judgment method.

Code tutorial for using PHP method to judge whether it is mobile login:

function is_mobile() {
    static $is_mobile;
    if (isset($is_mobile)) {
        return $is_mobile;
    }
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif
    (strpos($_SERVER['HTTP_USER_AGENT'], 
    'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 
    'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 
    'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'],
     'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'],
      'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 
      'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 
      'Opera Mobi') !== false
    ) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
 
    return $is_mobile;
}

This article This article introduces the code example of using PHP method to determine whether it is a mobile phone login. For more related content, please pay attention to the PHP Chinese website.

Related recommendations:

How to achieve infinite classification through PHP loops and recursion

Using magic methods in PHP_ _CLASS__ to obtain the related operations of the class name

How to obtain the openid and basic information of WeChat users through PHP

The above is the detailed content of How to determine whether it is a mobile phone login through PHP method (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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