PHP判断客户端是否为手机移动设备

2015/12/7 23:33:17 人评论 次浏览 分类:PHP

    有时候在开发的时候需要对手机移动端的浏览器进行判断,进行一下设备的判断进行一些适配的处理,本文就简单的通过PHP实现手机移动端的判断,代码很简单,这里直接贴代码。



//判断是否属手机设备
function is_mobile() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
    $is_mobile = false;
    foreach ($mobile_agents as $device) {
        if (stristr($user_agent, $device)) {
            $is_mobile = true;
            break;
        }
    }
    return $is_mobile;
}
//调用
if( is_mobile()){
 
}


相关资讯

  • PHP 判断网页请求是否是微信客户端

    最近在做微信的项目,需要深度地了解微信的特性,帮助客户开发出有价值的产品出来。今天项目中需要 PHP判断网页是否是微信打开

    2015/12/7 23:34:53
  • mysql 简单直接的登录方法和修改root密码的方法

    其实还是在迁站点的时候遇到的问题,一开始在新的服务器上安装mysql的时候就随便设置了密码,但是这次迁移我有很多站点,难道我要去改每个网站的配置文件,这样的改动量就很大了。所以还是用了最简单的方案,就是直接修改密码,使与原来的一致。

    2015/12/7 23:32:08
  • DedeCMS V5.7 与 PHP5.4 以上 出现的各种问题以及解决方案

    在给客户迁移PHP的网站的时候,发现网站的前端运行很正常,但是在后台的时候就出了问题,出现了标题不能为空的错误,还有登录成功之后无法跳到管理的页面,后面经过一番折腾终于找到一些相关的文章,这里总结一下。

    2015/12/7 23:30:50

共有访客发表了评论 网友评论

验证码: 看不清楚?