• php判断终端是手机还是电脑访问网站代码


    <?php 
    function check_wap() {  
        if (isset($_SERVER['HTTP_VIA'])) return true;  
        if (isset($_SERVER['HTTP_X_NOKIA_CONNECTION_MODE'])) return true;  
        if (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])) return true;  
        if (strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0) {  
            // Check whether the browser/gateway says it accepts WML.  
            $br = "WML";  
        } else {  
            $browser = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : '';  
            if(empty($browser)) return true;
            $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');  
                  
            $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');  
                  
            $found_mobile=checkSubstrs($mobile_os_list,$browser) ||  
                      checkSubstrs($mobile_token_list,$browser); 
            if($found_mobile)
                $br ="WML";
            else $br = "WWW";
        }  
        if($br == "WML") {  
            return true;  
        } else {  
            return false;  
        }  
    }
    
    function checkSubstrs($list,$str){
        $flag = false;
        for($i=0;$i<count($list);$i++){
            if(strpos($str,$list[$i]) > 0){
                $flag = true;
                break;
            }
        }
        return $flag;
    }
    
    if(check_wap()){
        echo "wap";
    }else{
    echo "web";
    }
    
    ?>
  • 相关阅读:
    更换pip源到国内镜像
    概率图模型学习笔记:HMM、MEMM、CRF
    xgboost入门与实战
    XGBoost浅入浅出
    使用word2vec训练中文词向量
    我为何放弃Gulp与Grunt,转投npm scripts(上)
    POJ 1265:Area
    Android网络缓存的实现思路
    设计模式:单例模式的写法(基础写法和线程安全写法)
    DFA 算法实现关键词匹配
  • 原文地址:https://www.cnblogs.com/shcolo/p/3331135.html
Copyright © 2020-2023  润新知