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;