在手机和完整网站之间切换 [英] Switch between mobile and full site

查看:83
本文介绍了在手机和完整网站之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

还有一个 index.php in m ,只需包含'front.html'。



该脚本可以检测用户的客户端并直接访问完整站点和移动网站自动。

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

如何处理? 您可以完成此操作通过设置一个cookie。

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

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



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

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


All my full site pages are under folder public_html, which contains index.php and folder m which contains all the mobile site pages. index.php is like this:

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

There is also an index.php in m, simply `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. However, if it is like <a href="../">switch to full site</a>, it will detect again and back to mobile site.

How to deal with that?

解决方案

You can accomplish this by setting a cookie.

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

Then from that php script, redirect to the home page.

In your index.php, check the cookie:

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

这篇关于在手机和完整网站之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆