【问题标题】:Switch between mobile and full site在移动网站和完整网站之间切换
【发布时间】:2011-12-11 01:35:16
【问题描述】:

我所有的完整网站页面都在文件夹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'。

此脚本可以检测用户的客户端并自动定向到完整站点和移动站点。

但现在我想要移动网站上的链接切换到完整网站。如果是&lt;a href="../front.html.php"&gt;switch to full site&lt;/a&gt;,地址栏中会有front.html.php,我不要这个。但是,如果是&lt;a href="../"&gt;switch to full site&lt;/a&gt;,它会再次检测并返回移动站点。

如何处理?

【问题讨论】:

  • 只是两个版本的设计不同?

标签: php html mobile


【解决方案1】:

您可以通过设置 cookie 来完成此操作。

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

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

在您的 index.php 中,检查 cookie:

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

【讨论】:

    【解决方案2】:

    创建会话变量 喜欢

    $_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>
    

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

    【讨论】:

    • 但是链接里的$_SESSION['base_url']是手机链接吧?
    • 不,当您更改视图时,base_url 的值将根据您的目录而变化
    • 是的。我想要移动页面上的链接,并链接到整个页面。
    • 如果页面在不同文件夹中具有相同的名称,这将为您完成
    • 但是当点击链接时,....front.html.php 仍然会出现在 url 中。因此我需要链接到文件夹而不是页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    相关资源
    最近更新 更多