在移动和全站点之间切换


Switch between mobile and full site

我所有的网站页面都在文件夹public_html下,其中包含index.php和文件夹m,其中包含所有的移动网站页面。index.php是这样的:

<?php
  if (...mobile client) {
    header('Location: m/');
  } else {
    include 'front.html.php';
  }
?>

m中也有一个index.php,只需' include 'front.html'。

该脚本可以检测用户的客户端,并自动跳转到完整站点和移动站点。

但现在我想在移动网站上的链接切换到完整的网站。如果像<a href="../front.html.php">switch to full site</a>,地址栏里就会有front.html.php,我不希望这样。但是,如果它像<a href="../">switch to full site</a>一样,它将再次检测并返回移动站点。

如何处理?

您可以通过设置cookie来实现这一点。

  setcookie("forceClient", "full", time()+3600);

然后从php脚本,重定向到主页。

在index.php中,检查cookie:

if($_COOKIE["forceClient"] == "full"){
  //logic
}

创建会话变量像

$_SESSION['viewer_type'] = "Mobile";

$_SESSION['viewer_type'] = "Regulare";

,然后定义一个新的变量,命名为base_url,并将其保存在会话中然后这样做

if($_SESSION['viewer_type'] == 'Mobile'):
     $_SESSION['base_url'] = "http://www.m.site.com/";
else:
     $_SESSION['base_url'] = "http://www.site.com/"; 
endif; 

链接现在将是

<a href="<?php echo $_SESSION['base_url'] ?>front.html.php">Test</a>

您需要在每次从移动视图变为常规视图或反之亦然时设置会话变量