discuz手机浏览切换到电脑版后无法再切换到手机版,原理分析

本文详细介绍了Discuz! 论坛系统中手机版与电脑版之间的切换原理,包括如何通过URL参数及Cookie进行版本切换,以及在不同版本下选择相应模板的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

切换原理

discuz手机版切换电脑版,底部链接:电脑版,url末尾添加参数mobile=no,
新页面会执行函数 source\class\discuz\discuz_application.php->init()->$this->_init_mobile()
if(getgpc('mobile') === 'no') {
dsetcookie('mobile', 'no', 3600);
$nomobile = true;
} elseif($this->var['cookie']['mobile'] == 'no' && getgpc('mobile') === 'yes') {
checkmobile();
dsetcookie('mobile', '');
} elseif($this->var['cookie']['mobile'] == 'no') {
$nomobile = true;
} elseif(!checkmobile()) {
$nomobile = true;
}
设置有效期为1小时的mobile=no的cookie。
如果没有传参数,根据mobile=no的cookie,
$nomobile = true;
在下面直接返回false;
并没有设置常量IN_MOBILE,
面在

页面在选择模板时,

if(defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || (isset($_G['forcemobilemessage']) && $_G['forcemobilemessage'])) {
$file = 'mobile/'.$oldfile;
}

只有IN_MOBILE被复制后,才会选择moblie手机模板。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值