How to detect for mobile phones and tablets using PHP

More and more people are using mobile phones and tablets to browse websites on the internet and if predictions are to be believed nearly 20% to 30% of sales are to come from these two devices in the next 3 to 5 years. Some website owners are converting their websites to responsive theme while others are creating separate mobile websites so that visitors are able to browse their websites and they don’t lose any sales. If you are a website owner who has separate websites for each medium (desktop and mobile) then follow the method defined below

  1. First download the PHP class library from Google Code.
  2. Copy the file on your server and include the file so that you are able to run the code on each script of your website.

Once done enter the following code

require_once("Mobile_Detect.php");

$detect = new Mobile_Detect();
if ( ($detect->isMobile()) || ($detect->isTablet()) ) {
       header("Location: ");
       exit;
}

Now if some one visits your website with a mobile phone or tablet then they will be directed to your mobile website while your desktop users would be able to browse normally as before.

Please follow and like us:

Be the first to comment

Leave a Reply

Your email address will not be published.


*