Saturday, April 28, 2012

Detect Android, iOS, Tablet and other mobile platforms using PHP Script!



In this article, I would let you know about one PHP class which you can use in your PHP script to detect various mobile platforms for your dynamic website. You can use this mobile detection script to configure your websites for most of major mobile platforms such as Android, iOS and tablets. Script is very easy t use and implement in few steps which are something like given below:



Steps to use PHP class for mobile detection:


Step 1: Download light weight PHP class from here.



Step 2: The name of file .PHP file would be something like "Mobile_Detect.php". Save this file in your webserver under root directory where other php pages of your website are located.



Step 3: Now, open index.php page i.e., home page of your website in a notepad or any other text editor like notepad++.



Step 4: To include the PHP detect class write following set of code on the top of your index.php file.



<?php
include('Mobile_Detect.php');
$detect = new Mobile_Detect();
?>


Step 5: Now right below this code, write down the following set of statements which are used to detect respective mobile platforms. You can write the appropriate code in the respective if blocks to make the look of website appropriate for that particular platform.

<?php
if($detect->iOS()){
// code to run for the Apple iOS platform.
}
if($detect->isAndroidOS()){
// code to run for the Google Android platform.
}

/* Other case insensitive available methods are isIphone(), isIpad(), isBlackBerry(), isKindle(), isOpera(), etc */

/* Alternatively, if you are only interested in checking to see if the user is using a mobile device, without caring for specific platform: */

if ($detect->isMobile()) {
// any mobile platform
}
if($detect->isTablet()){
// any tablet
}
?>


That's it. To know more platforms supported by this script, please refer the demo.php file in the zip folder.

Tags: , , , , ,

0 Responses to “Detect Android, iOS, Tablet and other mobile platforms using PHP Script!”

Post a Comment

Subscribe

Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio. Duis mollis

© 2013 Coolpctips. All rights reserved.
Designed by SpicyTricks