当前位置:首页 > Web开发 > 正文

‘ipad‘); //Search for iPad in user-agent if($androidTablet

2024-03-31 Web开发

//检测设备类型

function userAgent(){

## This credit must stay intact (Unless you have a deal with @lukasmig or [email protected]

## Made by Lukas Frimer Tholander from Made In Osted Webdesign.

## Price will be $2

     $ua = $_SERVER[‘HTTP_USER_AGENT‘];

    $iphone = strstr(strtolower($ua), ‘mobile‘); //Search for ‘mobile‘ in user-agent (iPhone have that)

    $android = strstr(strtolower($ua), ‘android‘); //Search for ‘android‘ in user-agent

    $windowsPhone = strstr(strtolower($ua), ‘phone‘); //Search for ‘phone‘ in user-agent (Windows Phone uses that)

     

     

    function androidTablet($ua){ //Find out if it is a tablet

        if(strstr(strtolower($ua), ‘android‘) ){//Search for android in user-agent

            if(!strstr(strtolower($ua), ‘mobile‘)){ //If there is no ‘‘mobile‘ in user-agent (Android have that on their phones, but not tablets)

                return true;

            }

        }

    }

    $androidTablet = androidTablet($ua); //Do androidTablet function

    $ipad = strstr(strtolower($ua), ‘ipad‘); //Search for iPad in user-agent

     

    if($androidTablet || $ipad){ //If it‘s a tablet (iPad / Android)

        return 0.75;

    }

    elseif($iphone && !$ipad || $android && !$androidTablet || $windowsPhone){ //If it‘s a phone and NOT a tablet

        //return ‘mobile‘;

        return 0.5;

    }else{ //If it‘s not a mobile device

        //return ‘desktop‘;

         return 1.0;

    }   

}

 

?>

<meta http-equiv="Content-type" content="initial-scale=<?php echo userAgent();?>, maximum-scale=1.0, user-scalable=no, width=device-width">

php检测设备类型

标签:

原文地点:https://www.cnblogs.com/saffibai/p/12246540.html

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30823.html