网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

phpcms移动化

感谢yidodo指点,才有此文。

成都创新互联公司专注于企业营销型网站、网站重做改版、北塔网站定制设计、自适应品牌网站建设、H5场景定制商城网站开发、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为北塔等各大城市提供网站开发制作服务。

思路如下:

1、自定义全局函数判断设备类型

2、pc访问为www域名,移动访问为wap域名

3、修改内容模型控制器,在选择模板的地方加上判断,如果是www域名则使用pc模板,如果是wap域名则使用移动模板。

好了就这样。

开始吧。判断设备类型的全局函数可以去网上找现成的。

function isMobile(){
    $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
    function CheckSubstrs($substrs,$text){
        foreach($substrs as $substr)
            if(false!==strpos($text,$substr)){
            return true;
        }
        return false;
    }
    $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
    $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
                           
    $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
    CheckSubstrs($mobile_token_list,$useragent);
                           
    if ($found_mobile){
        return true;
    }else{
        return false;
    }
}

放到phpcms/libs/function/extention.function.php中。

来到/phpcms/modules/content

新建 MY_index.php文件,内容如下。

db = pc_base::load_model('content_model');
$this->hosts = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
parent::__construct();
if(!strstr($this->hosts,'wap.')) $this->tomobile();
}
public function tomobile(){
$host = str_replace('www.','wap.',$this->hosts);
if(isMobile()){
header("Location: $host");
}
}
}
?>

修改/phpcms/modules/content/index.php 文件

凡是include template出现的地方都做一下判断。

if(strstr($this->hosts,'wap.')){
include template('content','shouyewap',$default_style);
}else{
include template('content','index',$default_style);
}

当然要解析一个wap域名过来用。

同理其实可以扩展到其他的前台模板中。

仅适用于动态网站。生成静态的是无法判断的。

完毕。


标题名称:phpcms移动化
当前URL:http://bjjierui.cn/article/jpjcij.html

其他资讯