文件下载链接
https://download.csdn.net/download/qq_39161501/11721012
\www\phpcms\modules\content\index.php
可直接下载文件,覆盖本地文件index.php文件
\www\phpcms\templates\default
新建content_m手机端模板文件夹
pc模板页面加入代码
\www\phpcms\templates\default \content
<script>
if(/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.location = "/index.php";
}
</script>
完成!
手动修改
\www\phpcms\modules\content\index.php 设置手机端
第一处:第31行的 include template('content','index',$default_style);
第二处:第203行 include template('content',$template);
第三处:第265行 include template('content',$template);
第四处:第278行 include template('content',$template);
替换为该代码
/*判断客户端*/
if(substr($_SERVER['SERVER_NAME'], 0,1) == 'm'){
include template('content_m','index',$default_style);
}elseif(stristr($_SERVER['HTTP_VIA'],"wap")){// 先检查是否为wap代理,准确度高
include template('content_m','index',$default_style);
}elseif(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){// 检查浏览器是否接受 WML.
include template('content_m','index',$default_style);
}elseif(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|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){//检查USER_AGENT
include template('content_m','index',$default_style);
}else{
include template('content','index',$default_style);
}
pc模板页面加入代码
\www\phpcms\templates\default \content
<script>
if(/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.location = "/index.php";
}
</script>