I need a tiny shove in the right direction on how to implement this prewritten mobile detection script. It comes up #1 on Google but it has no instructions. Could anybody help me with this?
http://mobiledetect.net/
Q1) I believe this code needs to be placed at the top of every HTML file on my site. But where in the HTML file do I place it? When I put it at the very top of my index.htm it doesn't run. The code prints out like plain text at the top of the webpage.
<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// change the mobile url here (between the quotes)
$mobileurl = "http://m.mywebsite.com";
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
if( $detect->isMobile()){
header("Location: " . $mobileurl,true, 301); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
}
?>
Q2) Mobile_Detect.php I believe I need to upload this file to my root directory. That's easy enough but does it need special permissions or something else? Right now permissions are set to 0644 on this file.
Q3) Do I need to update my .htaccess file which is blank? I'm hosting with GoDaddy so I believe it's on an Apache server.
Q4) Is there any other obvious thing that I'm missing?
Thanks a ton in advance!!!