Home  >  Article  >  Backend Development  >  How does php determine whether it is an instance of isPhone and is_weixin?

How does php determine whether it is an instance of isPhone and is_weixin?

黄舟
黄舟Original
2017-08-23 10:11:422175browse


  protected function isPhone(){
        $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
        //pc请求头信息数组
        $pc_arr=array('windows nt','macintosh','ipad','baiduspider','spider');
        //如确认为移动端则更改默认值
        //没找到pc数组元素时判断为移动端
        foreach($pc_arr as $k => $v){
           $pc=strpos($agent, $v) ? true : false;
           if($pc){
              return false;
           } 
        }
        return true;
    }


    /**
    * 判断是否微信
    * liangzheng 2014-12-03
    */
    protected function is_weixin(){
        if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
            return true;
        }
        return false;
    }

 

 

The above is the detailed content of How does php determine whether it is an instance of isPhone and is_weixin?. 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