zoukankan      html  css  js  c++  java
  • php如何判断电脑访问还是手机访问?

    手机上网用户数量越来越大,如今各网站都推出了手机网站,电脑用户访问时直接访问电脑版网页,当用户通过手机访问网站时则跳自动跳转到手机版网页,下面给大家分享一段php中判断电脑访问还是手机访问的代码:

    <?php
    //手机网页跳转
    //如果检测到访问的浏览器为下列一个指定的移动浏览器 则返回true
    function is_mobile(){
    	$regex_match="/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|";
    	$regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
    	$regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";   
    	$regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|";
    	$regex_match.="jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220";
    	$regex_match.=")/i";       
    	return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
    }
    	
    $is_mobile=is_mobile(); 
    
    if($is_mobile){
    	//这是一个手机浏览器,可以跳转到手机版网页
    	//header("Location: http://www.abc.com/3g");
    	echo "手机访问";
      }else{
    	//这不是一个手机浏览器
    	//header("Location: http://www.abc.com/desktop");
    	echo "电脑访问";
      }
    ?>
    
  • 相关阅读:
    (Ubuntu)下载及安装Genymosion模拟器并配置Android Studio
    ROS CMakeLists中target_link_libraries相对路径设置
    VS_C#快捷键
    一行代码实现各产品访问统计???[原创]
    PyCharm下载安装
    装饰模式(Decorator)
    Python之格式化输出
    python入门
    servlet--http接口简单的创建及调用
    Storm-jdbc-2讲 高级API及Trident
  • 原文地址:https://www.cnblogs.com/bluealine/p/6713250.html
Copyright © 2011-2022 走看看