简体   繁体   中英

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. 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
}

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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