Question

How can I handle the situation if the user wants from mobile to go to desktop site?

I am using this library for redirect to mobile, and how to create a redirect. The code below is that I am using mobile_detect.php library:

require_once 'controller/Mobile_Detect.php';
$detect = new Mobile_Detect;

// Any mobile device (phones or tablets).
if ( !$detect->isMobile() ) {

   //the link to mobile site

}

But how to handle vice versa?

Thanks for helping

Was it helpful?

Solution

<a href="self.php?desktop=1">Switch to desktop</a>

<?php
if(!isset($_SESSION['desktop'])) {
    $_SESSION['desktop'] = false;
}

if(isset($_GET['desktop']) && $_GET['desktop'] == 1) {
    $_SESSION['desktop'] = true;
}

if(!$_SESSION['desktop']) {
    if ( !$detect->isMobile() ) {

       //the link to mobile site

    }

}

On your mobile site you give the opportunity to people to switch to desktop (the page where the redirect is done) with passing a get parameter of desktop=1. Normally, if the parameter is not passed, and if the session is not set, it's false. On false value of $_SESSION['desktop'], you continue your script so it redirects to mobile. But once the param is passed, it changes the session to true, and you block will not be executed, so the normal (desktop) content of the site will be visible

OTHER TIPS

i use this

put this into your main site (non mobile)

    @include("Mobile_Detect.php");

$detect = new Mobile_Detect();

if ($detect->isMobile() && isset($_COOKIE['mobile']))

{

$detect = "false";

}

elseif ($detect->isMobile())

{
header("Location:http://whaterver.com");
}

then in your mobile app page put

<?php setcookie("mobile","m", time()+3600, "/",".whatever.com"); ?>

Then you can link back to the full site with a regular link because the "full site" will check for the cookie and wont redirect if its set. Which it will be because they mobile app page has set it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top