我的所有完整网站页面都在public_html
文件夹下,其中包含index.php
和文件夹m
,其中包含所有移动网站页面。 index.php
是这样的:
<?php
if (...mobile client) {
header('Location: m/');
} else {
include 'front.html.php';
}
?>
index.php
中还有m
,只是'包含'front.html'。
此脚本可以检测用户的客户端并自动指向整个站点和移动站点。
但现在我希望移动网站上的链接切换到完整网站。如果它与<a href="../front.html.php">switch to full site</a>
类似,地址栏中会有front.html.php
,我不希望这样。但是,如果它与<a href="../">switch to full site</a>
类似,则会再次检测并返回移动网站。
如何处理?
答案 0 :(得分:2)
您可以通过设置Cookie来完成此操作。
setcookie("forceClient", "full", time()+3600);
然后从该PHP脚本重定向到主页。
在index.php中,检查cookie:
if($_COOKIE["forceClient"] == "full"){
//logic
}
答案 1 :(得分:1)
制作会话变量 喜欢
$_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>
每次视图从移动设备更改为常规设置或反之亦然时,您需要设置会话变量