繁体   English   中英

使用php中的mobiledetect脚本,每24小时仅重定向一次页面

[英]redirect to page only once every 24 hour using mobiledetect script in php

我有以下代码:

include("Mobile_Detect.php");

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

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

用于移动检测:

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM