I'm developing a website which has a mobile counterpart. I have some code at the top of the page which detects if mobile, and redirects using the php header() command accordingly. I'm now looking at adding an option to 'switch to desktop version' on the mobile site, but then stay desktop.
I'm guessing I need to create a session variable named something like 'mobile' but I can't quite work out where I should place it.
Any advice would be amazing. Below is the code one each page. I am not positing the mobile_detect.php as it's rather long winded, but can be found at http://mobiledetect.net
<?php require_once('functions/Mobile_Detect.php');
$detect = new Mobile_Detect();
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
header("location:mobile/index.php");
}
?>
try
if ( !isset($_SESSION['forceDesktop']) )
$_SESSION['forceDesktop'] = false;
$detect = new Mobile_Detect();
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() && !$_SESSION['forceDesktop'] ){
header("location:mobile/index.php");
}
....
// some logic asking whether to force the desktop version
....
$_SESSION['forceDesktop'] = true;