PHPCMS手机网站二级域名的绑定
  • 分类:经验分享
  • 发表:2015-01-21
  • 围观(4,389)
  • 评论(0)

PHPCMS绑定手机网站的方法有两种,1是使用同一个域名,服务端直接识别客户端类型,跳转到不同的页面,2是绑定二级域名,访问时服务端根据域名跳转到指定的页面。

第一种方法:加载一个移动端识别程序,然后跳转,

具体如下:

1,下载识别程序mobile_device_detect.rar(在下面的附件中)

2,在程序中加入

  1. <?php
  2. //自动识别移动终端
  3. include('mobile_device_detect.php');
  4. mobile_device_detect(true,true,true,'/index.php?m=wap',false);
  5. ?>

即可。

如果生成静态的话,可以使用这个方法:

<!---识别手机或电脑的js开始--->
<script language="javascript">
(function(){
var res = GetRequest();
var par = res['index'];
if(par!='gfan'){
var ua=navigator.userAgent.toLowerCase();
var contains=function (a, b){
if(a.indexOf(b)!=-1){return true;}
};
var toMobileVertion = function(){
window.location.href = '/index.php?m=wap'
}

if(contains(ua,"ipad")||(contains(ua,"rv:1.2.3.4"))||(contains(ua,"0.0.0.0"))||(contains(ua,"8.0.552.237"))){return false}
if((contains(ua,"android") && contains(ua,"mobile"))||(contains(ua,"android") && contains(ua,"mozilla")) ||(contains(ua,"android") && contains(ua,"opera"))
||contains(ua,"ucweb7")||contains(ua,"iphone")){toMobileVertion();}
}
})();
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
</script>
<!---识别手机或电脑的js结束--->

JS代码贴上来有点乱了,,下面有下载,,

第二种就是绑定二级域名,

先在“后台-模块-手机门户-绑定域名”中绑定WAP页面需要用到的二级域名,如http://wap.zyxfw.com/,

然后找开/caches/configs/route.php,在

'default'=>array('m'=>'content', 'c'=>'index', 'a'=>'init'),

的后面加上

'wap.zyxfw.com'=>array('m'=>'wap', 'c'=>'index', 'a'=>'init','data'=>array('GET'=>array('siteid'=>1))),

如果是子站的WAP地址,就修改一下后面的'siteid'=>1即可。

这种方法面临同样一个问题,如果全站静态怎么办?只能用上面的方法了,,加入上面的JS代码。

jscode

mobile_device_detect

Top