1

I have the following code :

include("Mobile_Detect.php");

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

Which redirects website visitors to the mobile website if they are using a mobile device. the problem is that the code redirects all the time making it impossible for mobile users to access the computer website. I want the mobile users to have the option to go back to the normal website if they clicked on a button. but I cannot really do that because of the redirection code that I have now. How can I fix the code, so it will only redirect once every 24 hours. suggestions, ideas, solution, all are welcome.

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 に答える