我使用Mobile_Detect.php构建了一个移动检测,效果很好。现在,如果用户不想留在移动网站上,他可以点击“桌面版本”,然后通过设置$_SESSION['mobile'] = 'off'
的'mobile_off.php'返回主页面。
主站点执行以下代码:
<?php
session_start();
// Did the User come back from mobile.php?
if ($_SESSION['mobile'] != 'off') {
include 'Mobile_Detect/Mobile_Detect.php';
$detect = new Mobile_Detect();
// Smartphone?
if ($detect->isMobile() && !$detect->isTablet()) {
// Redirection --> echo 'JS'
echo "<script>window.location='mobile.php'</script>";
}
}
?>
问题似乎是if ($_SESSION['mobile'] != 'off')
被忽略或错误。我的iPhone总是直接送我回“mobile.php”。
有人可以帮忙吗?
也许我应该向您展示'mobile_off.php'中的代码:
<?php
session_start();
$_SESSION['mobile'] = 'off';
?>
答案 0 :(得分:1)
在检查会话变量的值之前,您需要首先检查会话变量是否存在。 要检查是否设置了会话变量,请尝试使用此代码
if(isset($_SESSION['mobile'])
之后检查会话变量的值