码迷,mamicode.com
首页 > Web开发 > 详细

php检测设备类型

时间:2020-01-31 20:40:23      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:win   max   stay   elseif   edit   pad   not   tab   name   

<?php
//检测设备类型
function userAgent(){
## This credit must stay intact (Unless you have a deal with @lukasmig or frimerlukas@gmail.com
## 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" name="viewport" content="initial-scale=<?php echo userAgent();?>, maximum-scale=1.0, user-scalable=no, width=device-width">

php检测设备类型

标签:win   max   stay   elseif   edit   pad   not   tab   name   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!