zoukankan      html  css  js  c++  java
  • discuz 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']));
    }

    然后是模板调用,调用代码:

    <!--{eval $is_mobile = is_mobile();}-->
    
    <!--{if $is_mobile}-->
    
    <!-- 显示此内容表示手机来路,让网站显示适合手机的内容 -->
    当然这里也可以用
    <!--{eval header("Location: http://www.juhutang.com/ ?手机版.html");}-->
    
    <!--{else}-->
    
    <!-- 显示此内容表示电脑来路,让网站显示适合电脑浏览的内容 -->
    <!--{eval header("Location: http://www.juhutang.com/ ?电脑版.html");}-->
    
    <!--{/if}-->

    也可以跳转,也可以显示内容,具体的随意了。

  • 相关阅读:
    oracle number数据类型
    codepage 和 charset
    嵌入式jetty的HTTP实现
    OpenCV For Java环境搭建与功能演示
    luogu P2783 有机化学之神偶尔会做作弊
    [国家集训队]稳定婚姻
    [SCOI2014]方伯伯运椰子
    [APIO2017]商旅
    luogu P1121 环状最大两段子段和
    [APIO/CTSC 2007]数据备份
  • 原文地址:https://www.cnblogs.com/php411161555/p/3877936.html
Copyright © 2011-2022 走看看