手机端跳转的一个小建议
By
迈达斯之手
at 2016-04-22 • 0人收藏 • 1941人看过
针对没有设置手机端域名的情况,主域名在被手机访问时也应该要加载为手机模板。
common.php(line755-794)
/* Set current template * default: PC Version * mobile: Mobile Version * api: API */ if ($IsApp) { ///balabalbala省略 } elseif ($_SERVER['HTTP_HOST'] == $Config['MobileDomainName']) { $TemplatePath = __DIR__ . '/styles/mobile/template/'; $Style = 'Mobile'; header('X-Frame-Options: SAMEORIGIN'); } else { $TemplatePath = __DIR__ . '/styles/default/template/'; $Style = 'Default'; header('X-Frame-Options: SAMEORIGIN'); //header('X-XSS-Protection: 1; mode=block'); //X-XSS-Protection may cause some issues in dashboard } $CurView = GetCookie('View', $IsMobile ? 'mobile' : 'desktop'); if ($Config['MobileDomainName'] && $_SERVER['HTTP_HOST'] != $Config['MobileDomainName'] && $CurView == 'mobile' && !$IsApp) { //如果是手机,则跳转到移动版,暂时关闭 header("HTTP/1.1 302 Moved Temporarily"); header("Status: 302 Moved Temporarily"); header('Location: ' . $CurProtocol . $Config['MobileDomainName'] . $RequestURI); exit(); }
主要是修改776行的条件判断:
/* Set current template * default: PC Version * mobile: Mobile Version * api: API */ $CurView = GetCookie('View', $IsMobile ? 'mobile' : 'desktop'); if ($IsApp) { //balabalabla省略 } elseif ($_SERVER['HTTP_HOST'] == $Config['MobileDomainName'] || $CurView == 'mobile') { $TemplatePath = __DIR__ . '/styles/mobile/template/'; $Style = 'Mobile'; header('X-Frame-Options: SAMEORIGIN'); } else { $TemplatePath = __DIR__ . '/styles/default/template/'; $Style = 'Default'; header('X-Frame-Options: SAMEORIGIN'); //header('X-XSS-Protection: 1; mode=block'); //X-XSS-Protection may cause some issues in dashboard } if ($Config['MobileDomainName'] && $_SERVER['HTTP_HOST'] != $Config['MobileDomainName'] && $CurView == 'mobile' && !$IsApp) { //如果是手机,则跳转到移动版,暂时关闭 header("HTTP/1.1 302 Moved Temporarily"); header("Status: 302 Moved Temporarily"); header('Location: ' . $CurProtocol . $Config['MobileDomainName'] . $RequestURI); exit(); }
5 个回复 | 最后更新于 2016-04-22
回复#1 @lincanbin :
这样写会不会手机页面里的“桌面模式”用不了了?
http://www.94cb.com/view-desktop?callback=%2F
毕竟它是通过cookie强制切换的
登录后方可回帖
实际上应该这么写。