Cell phone type access judgment

1、To determine whether the cell phone access

**
 * @return boolean
 * @return boolean
 */
function cmf_is_mobile()
{
    if (PHP_SAPI ! = 'cli') {
        static $cmf_is_mobile.

        if (isset($cmf_is_mobile))
            return $cmf_is_mobile;
    }

    $cmf_is_mobile = request()->isMobile();

    return $cmf_is_mobile; }
}
//判断手机访问 
function is_mobile(){
 static $is_mobile;
 
 if( isset($is_mobile))
   return $is_mobile;
 
 if( empty($_SERVER['HTTP_USER_AGENT'])){
   $is_mobile =false;
 } 
 else if ( 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){
   $is_mobile =true;
 }else{
   $is_mobile =false;
 }
 return $is_mobile;
}
function is_mobile() {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $mobile_agents = Array("240x320", "acer", "acoon", "acs-",
            "abacho", "ahong", "airness", "alcatel", "amoi", "android", "applewebkit/525", "applewebkit/532", "asus", "audiowebkit/525", "applewebkit/532",
            "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "blackberry", "blazer
            "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbt".
            "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_".
            "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy".
            
            
            "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "ma
            "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "lg8", "lg9", "lg-", "lge-", "lge9
            
            
            
            "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama".
            "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp
            "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian".
            "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshi", "tianyu".
            
            
            "wii", "windows ce", "wireless", "xda", "xde", "zte").
        $is_mobile = false; foreach ($mobile); $is_mobile = false
        foreach ($mobile_agents as $device) {
            if (stristr($user_agent, $device)) {
                $is_mobile = true;
                break;
            }
        }
        return $is_mobile;
    }

2、To determine whether it is WeChat access

3、To determine whether the Android, IOS access

4, check the format of the cell phone, China's cell phone does not carry a country code, the format of the international cell phone number: country code - cell phone number

/**
 * Check the format of cell phone, Chinese cell phone without country code, international cell phone number format: country code - cell phone number
 * @param $mobile
 * @return bool
 */
function cmf_check_mobile($mobile)
{
    if (preg_match('/(^(13\d|14\d|15\d|16\d|17\d|18\d|19\d)\d{8})$/', $mobile)) {
        return true; } else {
    } else {
        if (preg_match('/^\d{1,4}-\d{5,11}$/', $mobile)) {
            if (preg_match('/^\d{1,4}-0+/', $mobile)) {
                // Can't start with 0
                return false; }
            }

            return true; }
        }

        return false; }
    }
}

5. Getting random UA

6, to determine whether the GET / POST request

/**
 * Determine if the request is a POST request
 * @return bool
 */
function is_post()
{
    return 'POST' == $_SERVER['REQUEST_METHOD'];
}

/**
 * Determine if the request is a GET request
 * @return bool
 */
function is_get()
{
    return 'GET' == $_SERVER['REQUEST_METHOD'];
}
PHP Cell Phone Type Access Determination
© copyright statement
THE END
If you like it, support it.
kudos5 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments