JS代码 ( 推荐 )
- 船说用户将此代码复制到 tpl_header.php 模板文件中(推荐)
- 或去掉前后的 <script> 放入 /www/static/模板文件夹/common.js 最前面
<script> if(navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null){ //判断是否为移动端 if( window.location.host != 'm.xxx.com' ){ window.location = 'http://m.xxx.com' + window.location.pathname; //带路径跳转 } } </script>
PHP代码( 不建议 )
function ismobile(){ if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { return true; } else { if (isset($_SERVER['HTTP_VIA']) && stripos($_SERVER['HTTP_VIA'], 'wap') !== false) { return true; } else { if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|phone|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|wap|windows ce|xda |xda_|xoom)/i', $_SERVER['HTTP_USER_AGENT'])) { return true; } else { if (isset($_SERVER['HTTP_ACCEPT']) && stripos($_SERVER['HTTP_ACCEPT'], 'text/html') === false && (stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false || stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.xhtml+xml') !== false)) { return true; } else { return false; } } } } }
原创文章,作者:Tony,如若转载,请注明出处:https://www.xxside.com/4185.html
思德心语,壹群:799239814