zoukankan      html  css  js  c++  java
  • php 验证访问浏览器是电脑还是手机

    //判断如果为手机用户则

    if(checkmobile()==true) {

    $url=$_SERVER["HTTP_HOST"]; 

    $urlHost=GetHost($url); 

    header("Location:http://wap.".$urlHost."");

    }

    //验证电脑或者是手机

    function checkmobile() {  //注释手机验证 

    //return true;

     global $_G; 

    $mobile = array();

     static $touchbrowser_list =array('iphone', 'android', 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini',  'ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung',     'palmsource', 'xda', 'pieplus', 'meizu', 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser',     'up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource',     'alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone',     'iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop',     'benq', 'haier', '^lct', '320x320', '240x320', '176x220', 'windows phone');  static $wmlbrowser_list = array('cect', 'compal', 'ctl', 'lg', 'nec', 'tcl', 'alcatel', 'ericsson', 'bird', 'daxian', 'dbtel', 'eastcom',    'pantech', 'dopod', 'philips', 'haier', 'konka', 'kejian', 'lenovo', 'benq', 'mot', 'soutec', 'nokia', 'sagem', 'sgh',    'sed', 'capitel', 'panasonic', 'sonyericsson', 'sharp', 'amoi', 'panda', 'zte');

     static $pad_list = array('ipad');

     $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);

     if(dstrpos($useragent, $pad_list))

    {   return false;  }

     if(($v = dstrpos($useragent, $touchbrowser_list, true)))

    {   $_G['mobile'] = $v;   return '2';  } 

    if(($v = dstrpos($useragent, $wmlbrowser_list)))

    {  

    $_G['mobile'] = $v; 

     return '3'; //wml版

     }

     $brower = array('mozilla', 'chrome', 'safari', 'opera', 'm3gate', 'winwap', 'openwave', 'myop');

     if(dstrpos($useragent, $brower)) return false;

     $_G['mobile'] = 'unknown';

     if(isset($_G['mobiletpl'][$_GET['mobile']]))

    {   return true;  }

    else

    {   return false;  }

    }

    function dstrpos($string, $arr, $returnvalue = false) {

     if(empty($string)) return false;

     foreach((array)$arr as $v)

     if(strpos($string, $v) !== false)

    {   

    $return = $returnvalue ? $v : true;   

    return $return;  

    }  return false;

    }

    //截取网站主域名

    function GetHost($url)

    {  

      $num=substr_count($url,'.');  

      if($num>1)   

      {      

          $strNum=strpos($url,'.'); 

           $strCount=strlen($url);      

          $endNum=$strCount-$strNum;     

        $url=substr($url,($strNum+1),$endNum);         

       }  

      return $url;

    }

  • 相关阅读:
    BZOJ1854: [Scoi2010]游戏
    NOIP2017 【游记】
    NOIP2017 考前汇总
    最长上升子序列nlogn算法
    BZOJ3110 K大数查询 【线段树 + 整体二分 或 树套树(非正解)】
    BZOJ1089 [SCOI2003]严格n元树 【dp + 高精】
    BZOJ1072 排列perm 【状压dp】
    NOIP2003 传染病控制 【搜索 + 卡时】
    BZOJ 1070 修车 【费用流】
    [SCOI2005]最大子矩阵
  • 原文地址:https://www.cnblogs.com/bk7788/p/5692145.html
Copyright © 2011-2022 走看看