Reputation: 4132
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?
Upvotes: 1
Views: 2603
Reputation: 2763
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
Upvotes: 1
Reputation: 8198
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
}
Upvotes: 2