[英]Redirect loop in full site to mobile site using session
我有一個完整的網站,該網站已經在OS-Commerce中使用,而移動網站則在核心PHP(codeignitor)中,並且完整版和移動版位於子域上。
例如完整網站: www.example.com
而移動網站域名是m.example.com
。 當用戶在移動設備中打開整個站點域時,網站將重定向適當的移動域,但是如果移動用戶要查看完整站點,則用戶可以在移動設備中查看完整站點。
我已經使用它來完成重定向http://code.google.com/p/php-mobile-detect/ ,但是它不是使用會話重定向到完整站點或移動站點。 我知道我必須使用PHP SESSIONS和REQUEST才能使其正常工作,但是我不確定如何在這種情況下使用它們,所以請您提出如何使用會話解決重定向問題的建議?
這是我的代碼:
session_start();
include('includes/Mobile_Detect.php');
$detect = new Mobile_Detect;
if(isset($_REQUEST['fullsite']) && $_REQUEST['fullsite'] == 'yes')
{//check if fullsite view request from mobile or website?
$_SESSION['fullsite']="yes";
if($detect->isMobile()) {
$_SESSION['website']="mobile";
}
else{
$_SESSION['website']="computer";
}
$deviceType = header('Location: https://www.example.com/');
}
else
{
if($_SESSION['website'] =="mobile" && $_SESSION['fullsite'] !="yes")
{
if($detect->isTablet())
{
$deviceType = 'tablet';
}
else
{
$deviceType = 'phone';
}
$deviceType = header('Location: https://m.example.com/');
}
elseif($_SESSION['website'] =="computer" && $_SESSION['fullsite'] =="yes")
{
$deviceType = 'computer';
$deviceType = header('Location: https://www.example.com/');
}
else{
$deviceType = 'computer';
}
$scriptVersion = $detect->getScriptVersion();
session_destroy();
}
從我可以從github頁面獲得的信息中,您應該能夠像下面這樣工作:
index.php
session_start();
if ($_GET['fullscreen'] == 'yes') {
$_SESSION['fullscreen'] = 1;
} else if ($_GET['fullscreen'] == 'no') {
$_SESSION['fullscreen'] = 0;
}
if (false == isset($_SESSION['fullscreen']) && ($_SESSION['fullscreen'] == 0)) {
// If session['fullscreen'] has not been set (maybe first visit
// or the user does not what in fullscree
// check the device and do redirect
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
...
}
// Other code here
從移動設備訪問時,如果用戶想要完整版本,請提供錨定以GET參數url的網址fullscreen=yes
( http://example.com?fullscreen=yes )如果在完整站點上並檢測到移動設備(上述代碼中未包括) ),則可以提供指向fullscreen=no
移動版本的鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.