php 判断访问是否是手机或者pc

php代码

function isMobile() {
    $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;
}

原文地址:https://www.cnblogs.com/wen-zi/p/9056044.html

时间: 2024-09-30 20:00:36

php 判断访问是否是手机或者pc的相关文章

php或js判断网站访问者来自手机或者pc机

php或js判断网站访问者来自手机或者pc机 针对不同平台选择不同的网站版本,最终总结如下: 一.JS版代码: <!--切换手机版网站---> <script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script> <script type="text/javascript&

判断客户端是否是手机或者PC

/// <summary> /// 判断客户端是否是手机或者PC /// </summary> /// <returns></returns> public static bool IsMobileDevice() { HttpContext context = HttpContext.Current; //C#自带方法判断是否为移动端 if (context.Request.Browser.IsMobileDevice) { return true; }

判断当前终端是手机还是pc端并进行不同的页面跳转

判断当前设备(终端)是手机还是pc端并进行不同的页面跳转 DEMO 1 <script type="text/javascript"> function browserRedirect() { var sUserAgent= navigator.userAgent.toLowerCase(); var bIsIpad= sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs= sUserAgent.mat

php或js判断网站访问者来自手机或者pc端源码

很多时候也可以通过逻辑程序来进行判断,如PHP.JS是常用的两种识别访问设备类型的常用方法. 原理都是采用识别访问客户端的HTTP_USER_AGENT,然后进行关键字匹配进行确定设备类型,对于伪造HTTP头的就区分不出来了. 区分设备类型然后要做的就是能够针对不同设置显示出易于阅读的网页,具体可以研究响应式布局技术. 本文主要介绍如何通过php或js来识别终端类型. <?php class IsMobile { public static function isMobile() { $user

java判断request请求是手机还是pc终端

/** * 判断请求是否手机端 * @param req * @return */ public static boolean isMobile(HttpServletRequest req) { UserAgent ua = UserAgent.parseUserAgentString(req.getHeader("User-Agent")); OperatingSystem os = ua.getOperatingSystem(); if(DeviceType.MOBILE.equ

thinkphp 检测访问来源是来自手机还是PC

/** * 判断访问是不是来自手机 * @param * @author Julian */function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:''; function Check

nginx规则:自动降级,手机用户访问跳转手机版与PC版页面

工作中为满足业务需要以及保证服务的可用性,配置的一些nginx跳转规则,与公司业务相关信息已经抹去,提供出来希望对大家有帮助. 1. 当后端服务器出现异常,响应码为500 501 502 503 504,请求转发到静态降级服务器,从而保证业务不至于完全无法访问,对于浏览型且实时性要求不高的站点非常有用. app_servers:应用服务器,提供正常服务页面 shopwebstatic:静态服务器,提供定时爬取的静态页面 2.请求重试: proxy_next_upstream          

PHP和JS判断访问客户端的是PC还是移动设备

js判断 <script type="text/javascript"> function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "ip

【JS】【19】使用Jquery判断是电脑或手机或微信浏览器访问

正文: //检测平台 var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac = p.indexOf("Mac") == 0; system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); system.ipad = (navigator.userAgent.match(/iPad/i