【问题标题】:Mobile Redirect, then wanting to return to Desktop version and stay there.移动重定向,然后想要返回桌面版本并留在那里。
【发布时间】:2014-01-14 14:12:54
【问题描述】:

我正在开发一个拥有移动版的网站。我在页面顶部有一些代码可以检测是否移动,并相应地使用 php header() 命令进行重定向。我现在正在考虑在移动网站上添加一个“切换到桌面版本”的选项,然后保持桌面。

我猜我需要创建一个名为“mobile”之类的会话变量,但我不知道应该把它放在哪里。

任何建议都会很棒。下面是每一页的代码。我没有设置 mobile_detect.php,因为它相当冗长,但可以在 http://mobiledetect.net

找到
<?php require_once('functions/Mobile_Detect.php'); 

$detect = new Mobile_Detect();
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
header("location:mobile/index.php");
}
?>

【问题讨论】:

    标签: php redirect mobile desktop


    【解决方案1】:

    试试

    if ( !isset($_SESSION['forceDesktop']) )
        $_SESSION['forceDesktop'] = false;
    
    $detect = new Mobile_Detect();
    // Exclude tablets.
    if( $detect->isMobile() && !$detect->isTablet() && !$_SESSION['forceDesktop'] ){
        header("location:mobile/index.php");
    }
    .... 
    
    // some logic asking whether to force the desktop version
    ....
         $_SESSION['forceDesktop'] = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 2012-12-23
      • 2013-02-18
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多