PHP - Directing Mobiles and Tablets

PseudZ

Expert Member
Joined
May 28, 2008
Messages
1,217
#1
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.

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!
 
Joined
Aug 22, 2003
Messages
19,809
#4
What does the multipad show in the header? check the source code of mobile_detect.php, I can see Android ICS 4.0 tested on a Samsung Galaxy?

Since the source code is freely available, once you determined the header your tablet includes, you can add it to there
 

PseudZ

Expert Member
Joined
May 28, 2008
Messages
1,217
#5
Ah that makes sense.

It seems the header is:

Code:
Mozilla/5.0 (Linux; Android 4.0.3; PMP3370B Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19
How would I list it in mobile_detect.php? Not too sure on the entry method.
 
Joined
Aug 22, 2003
Messages
19,809
#6
I'd guess in this line?

PHP:
'GenericTablet'     => 'Android.*\b97D\b|Tablet(?!.*PC)|ViewPad7|MID7015|BNTV250A|LogicPD Zoom2|\bA7EB\b|CatNova8|A1_07|CT704|CT1002|\bM721\b|hp-tablet',
Maybe try and Google how to add to mobile_detect.php as I'm sure you're not the only one with that issue
 
Top