强制“访问完整站点”链接以始终显示完整站点


Force "visit full site" link to show full site all the time

这是我的代码。 有人在PHP重定向方面遇到了问题,所以我只是通过一个JS重定向并注释掉另一个。

因此,当我在手机上(WP8)时,如果我打开了"首选移动网站",即使使用下面的代码,我也会卡在移动网站"m.smsalem.com"上。但是,如果我将其更改为"首选桌面网站",我会先获得移动网站,可以单击"访问完整网站",然后我可以查看常规网站。

知道我还能做些什么来迫使那些设置了"首选移动网站"的人在点击该链接时访问常规网站吗?

<?php
include 'http://smsalem.com/Mobile_Detect.php';
$detect = new Mobile_Detect();
if(strpos($_SERVER['HTTP_REFERER'], 'm.smsalem.com')){
    setcookie("noMobile", true, time()+86400);  /* expire in 1 hour */
}
if ($detect->isMobile()) {
    if(!isset($_COOKIE['noMobile'])){
        ?>
        <script type="text/javascript">
            if (screen.width <= 700) {
            window.location = "http://m.smsalem.com";
        }
    </script>
    <?php
        //header('Location: m.smsalem.com');
        //exit(0);
      }
} ?>

正如 Marc B 已经提到的,您设置的 cookie 在您进行刷新之前不可用。如果您只将cookie设置为一小时,那么为什么不使用 SESSION ,这是直接可用的。

然后,您的代码将如下所示:

<?php
include 'http://smsalem.com/Mobile_Detect.php';
$detect = new Mobile_Detect();
if(strpos($_SERVER['HTTP_REFERER'], 'm.smsalem.com')){
    $_SESSION["noMobile"] = true;
}
if ($detect->isMobile()) {
    if(!isset($_SESSION["noMobile"])){
        ?>
        <script type="text/javascript">
            if (screen.width <= 700) {
            window.location = "http://m.smsalem.com";
        }
    </script>
    <?php
        //header('Location: m.smsalem.com');
        //exit(0);
      }
} ?>

就个人而言,我会使用 PHP header()来重定向用户。但是,您将无法在重定向之前检查屏幕宽度。

相关文章: