1

我有以下代码:

include("Mobile_Detect.php");

$detect = new Mobile_Detect();
if ($detect->isMobile()) {
$parsedUrll = curPageURL();
$wwwtom = str_replace("www", "m", $parsedUrll);
header("location: $wwwtom");
exit;
}

如果他们使用移动设备,它将网站访问者重定向到移动网站。问题是代码一直在重定向,使移动用户无法访问计算机网站。我希望移动用户在点击按钮后可以选择返回正常网站。但由于我现在拥有的重定向代码,我不能真正做到这一点。我该如何修复代码,所以它只会每 24 小时重定向一次。欢迎提出建议,想法,解决方案。

4

1 回答 1

3

将此用于移动检测:

include 'Mobile_Detect.php';

$detect = new Mobile_Detect();
if ($detect->isMobile() && !isset($_COOKIE['use_desktop'])) // check if mobile and does not prefer desktop
{
    $parsedUrll = curPageURL();
    $wwwtom = str_replace('www', 'm', $parsedUrll);
    header("Location: $wwwtom");
    exit;
}

使用这样的链接进入桌面,或使用$_GET查询:

<a href='desktop.php'>View Desktop Version</a>

desktop.php使用这个:

define('COOKIE_LIFETIME_ONE_DAY', $_SERVER['REQUEST_TIME'] + 86400);
setcookie('use_desktop', '1', COOKIE_LIFETIME_ONE_DAY);
header("Location: http://www.mysite.com/"); // direct to desktop site
exit;
于 2013-01-05T01:41:59.587 回答