Giarc86
Expert Member
- Joined
- May 28, 2008
- Messages
- 1,243
- Reaction score
- 4
Hi all,
I am having a slight problem with this. Hopefully someone can help.
Currently I have mobile visitors to my sites main page directed to the mobile site. There is a link (/?mobile=false) there where they can go back to the main site if they wish which is set by a cookie. This is all working 100%. The problem I am having is that I don't want any tablets to direct to the mobile site, they must stay on the main site.
My code looks as if it shouldn't be directing them but whatever I try I can't get them to stay on the main site.
I am using the mobile_detect.php class to detect.
Thanks for any help!
I am having a slight problem with this. Hopefully someone can help.
Currently I have mobile visitors to my sites main page directed to the mobile site. There is a link (/?mobile=false) there where they can go back to the main site if they wish which is set by a cookie. This is all working 100%. The problem I am having is that I don't want any tablets to direct to the mobile site, they must stay on the main site.
My code looks as if it shouldn't be directing them but whatever I try I can't get them to stay on the main site.
I am using the mobile_detect.php class to detect.
PHP:
<?php
@include("Mobile_Detect.php");
$detect = new Mobile_Detect();
$mobile_cookie = isset($_COOKIE['mobile'])? $_COOKIE['mobile'] : "";
$force_mobile = ($mobile_cookie == "true") ? true : false;
if (isset($_GET['mobile'])) {
if ($_GET['mobile'] == 'true') {
setcookie("mobile", "true", time() + 31536000, "/");
$force_mobile = true;
} else {
setcookie("mobile", "false");
$force_mobile = false;
}
}
if ($force_mobile){
header("Location:http://mobilesite.mobi");
} else {
if ($detect->isMobile()){
if ($mobile_cookie == "" && !$detect->isTablet()){
header("Location:http://mobilesite.mobi");
}
}
}
?>
Thanks for any help!