Skip to content

Instantly share code, notes, and snippets.

@openprojdev
Created July 11, 2013 14:32
Show Gist options
  • Save openprojdev/5975977 to your computer and use it in GitHub Desktop.
Save openprojdev/5975977 to your computer and use it in GitHub Desktop.
Mobile Request Redirection using WURFL Lib, and Tera Wurfl PHP Lib http://wurfl.sourceforge.net
//Set mobile check to true
$mobile_check = true;
if (preg_match('/bot|ipad|xoom|sch-i800|playbook|tablet|kindle/i',$_SERVER['HTTP_USER_AGENT'])) {
$mobile_check = false;
}
if ( isset($_GET['desktop']) && !empty($_GET['desktop']) ) {
$mobile_check = false;
setcookie('desktop', 1);
}
if ( isset($_COOKIE['desktop']) && !empty($_COOKIE['desktop']) ) {
$mobile_check = false;
}
if ($mobile_check == true ) {
# Mobile redirection using WURFL Lib and database downloaded from http://wurfl.sourceforge.net
require_once './Tera-Wurfl/TeraWurfl.php';
$wurflObj = new TeraWurfl();
$wurflObj->getDeviceCapabilitiesFromAgent();
if($wurflObj->getDeviceCapability("is_wireless_device")){
header("Location: http://mobilesite" . $_SERVER['REQUEST_URI']);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment