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}-->

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

原文地址:https://www.cnblogs.com/php411161555/p/3877936.html