船说CMS通过判断访问设备,PC端跳转到移动端实现(JS+PHP)

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

 

1 本站资源大多存储在云盘,如发现链接失效、缺集无法播放私信反馈。
2 连载中的有声书每月不定时更新一次,想在线收听下载百度网盘APP或者天翼网盘APP
3 本站部分资源来源于网络,版权归原作者所有,若有侵犯您的权利,请来信告知,我们将立即予以删除。
船说CMS通过判断访问设备,PC端跳转到移动端实现(JS+PHP)-听书迷
北宋小厨师有声小说全集_漫天雨播讲
精品有声小说(www.lrts.vip)
RMB8
限时特惠
RMB25
仅供下载学习、请支持正版!
付费资源
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
Worrying does not empty tomorrow of its troubles, it empties today of its strength.
担忧不会清空明日的烦恼,它只会丧失今日的勇气
评论 抢沙发
头像
禁止纯数字、英文等无意义的评论内容,一经发现禁言7天!
提交
头像

昵称

取消
昵称表情

    暂无评论内容