Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 移动重定向,然后想要返回到桌面版本并停留在那里。_Php_Redirect_Mobile_Desktop - Fatal编程技术网

Php 移动重定向,然后想要返回到桌面版本并停留在那里。

Php 移动重定向,然后想要返回到桌面版本并停留在那里。,php,redirect,mobile,desktop,Php,Redirect,Mobile,Desktop,我正在开发一个网站,其中有一个手机对应。我在页面顶部有一些代码,可以检测是否移动,并相应地使用php header命令重定向。我现在正在考虑在移动站点上添加一个“切换到桌面版本”的选项,但之后将其保留在桌面上 我猜我需要创建一个名为“mobile”的会话变量,但我不太清楚应该把它放在哪里 任何建议都会令人惊讶。以下是每页的代码。我不认为mobile_detect.php是冗长的,但可以在 试一试 <?php require_once('functions/Mobile_Detect.php

我正在开发一个网站,其中有一个手机对应。我在页面顶部有一些代码,可以检测是否移动,并相应地使用php header命令重定向。我现在正在考虑在移动站点上添加一个“切换到桌面版本”的选项,但之后将其保留在桌面上

我猜我需要创建一个名为“mobile”的会话变量,但我不太清楚应该把它放在哪里

任何建议都会令人惊讶。以下是每页的代码。我不认为mobile_detect.php是冗长的,但可以在

试一试

<?php require_once('functions/Mobile_Detect.php'); 

$detect = new Mobile_Detect();
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
header("location:mobile/index.php");
}
?>
if ( !isset($_SESSION['forceDesktop']) )
    $_SESSION['forceDesktop'] = false;

$detect = new Mobile_Detect();
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() && !$_SESSION['forceDesktop'] ){
    header("location:mobile/index.php");
}
.... 

// some logic asking whether to force the desktop version
....
     $_SESSION['forceDesktop'] = true;