简体   繁体   English

在移动和完整站点之间切换

[英]Switch between mobile and full site

All my full site pages are under folder public_html , which contains index.php and folder m which contains all the mobile site pages. 我所有的完整网站页面都在public_html文件夹下,该文件夹包含index.php而文件夹m包含所有移动网站页面。 index.php is like this: index.php是这样的:

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

There is also an index.php in m , simply `include 'front.html'. m还有一个index.php ,只需`include'front.html'。

This script can detect user's client and direct to full site and mobile site automatically. 该脚本可以检测用户的客户端并自动定向到完整站点和移动站点。

But now I want a link on the mobile site to switch to full site. 但是现在我希望移动网站上的链接切换到完整网站。 If it is like <a href="../front.html.php">switch to full site</a> , there will be front.html.php in the address bar, and I don't want this. 如果它像<a href="../front.html.php">switch to full site</a> ,地址栏中会有front.html.php ,我不希望这样。 However, if it is like <a href="../">switch to full site</a> , it will detect again and back to mobile site. 但是,如果像<a href="../">switch to full site</a> ,它将再次检测并返回到移动网站。

How to deal with that? 怎么处理?

You can accomplish this by setting a cookie. 您可以通过设置cookie来完成此操作。

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

Then from that php script, redirect to the home page. 然后从该PHP脚本,重定向到主页。

In your index.php, check the cookie: 在index.php中,检查cookie:

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

Make a session variable like 创建一个会话变量

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

or 要么

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

and then define a new variable call it base_url and save it in the session also and do this 然后定义一个新变量,将其命名为base_url并将其保存在会话中并执行此操作

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

the link now will be 现在链接将是

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

You need to set the session variable each time the view changed from mobile to regular or visa versa 您需要在每次视图从移动设备更改为常规视图时都设置会话变量,反之亦然

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM