[英]Switch between mobile and full site
我所有的完整網站頁面都在public_html
文件夾下,該文件夾包含index.php
而文件夾m
包含所有移動網站頁面。 index.php
是這樣的:
<?php
if (...mobile client) {
header('Location: m/');
} else {
include 'front.html.php';
}
?>
在m
還有一個index.php
,只需`include'front.html'。
該腳本可以檢測用戶的客戶端並自動定向到完整站點和移動站點。
但是現在我希望移動網站上的鏈接切換到完整網站。 如果它像<a href="../front.html.php">switch to full site</a>
,地址欄中會有front.html.php
,我不希望這樣。 但是,如果像<a href="../">switch to full site</a>
,它將再次檢測並返回到移動網站。
怎么處理?
您可以通過設置cookie來完成此操作。
setcookie("forceClient", "full", time()+3600);
然后從該PHP腳本,重定向到主頁。
在index.php中,檢查cookie:
if($_COOKIE["forceClient"] == "full"){
//logic
}
創建一個會話變量
$_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>
您需要在每次視圖從移動設備更改為常規視圖時都設置會話變量,反之亦然
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.