Mobile Detect with PHP

Mobile Detect with PHP

In this modern era, the web has now gone mobile. i.e. website are made keeping in mind that people will be accessing them via their mobiles phones and tablets. Although website are made with the css media queries which respond to the devices, it does not gives minute details of the user devices like their version, platform, etc. Using Mobile detect with PHP library we can get details of their devices like their platform, versions, browsers etc. It helps in keeping track of the data which will benefit the website owner.

View Demo

What is Mobile Detect Library?

Mobile Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. It is a pure PHP library and works on server side, it is not a replacement for Responsive Web Design (media queries) or other forms of client-side feature detection. This library has been used on various open source project like Prestashop, concrete5.

Detect your device with Mobile Detect

Mobile Detect Library will check whether your device is a mobile, tablet or a computer. To use it in your program use the code below.

require_once 'Mobile_Detect.php';

$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');

 * Can be computer
 * Can be mobile
 * Can be tablet
echo $deviceType;

Check if the device is mobile (phone or tablet).
if ( $detect->isMobile() ) {
 // your code

Check if the device is tablet.
if( $detect->isTablet() ){
 // your code

Check if the device is phone, not tablet.
if( $detect->isMobile() && !$detect->isTablet() ){
 // your code

Check device platform like iphone, android phone, Windows, Symbian.
// Check for a iphone
if( $detect->isiOS() ){
 // your code 

// if andriod phone
if( $detect->isAndroidOS() ){
 // your code

// if java phone
if( $detect->isJavaOS() ){
 // your code

// if windows phone
if( $detect->isWindowsPhoneOS() ){
 // your code

// if symbian phone
if( $detect->isSymbianOS() ){
 // your code

There are other custom detection methods to do more task. Have a look at few of them.

Check out the demo and download the script below.

View Demo

Share to download the Source Codes for FREE!
We're glad to give free downloads, but we need your love to carry on making that.
Please support us by sharing the page.

Get the latest updates directly in your inbox for FREE: Subscribe here

Share your feedback / let me know your doubts regarding this tutorial in the comment box given below.


Shahrukh Khan (Hasan)

A software engineer who's a die-hard coder, blogger, dreamer and mentor with years of expertise in web development. Know more...

Related Posts

Khurshid Md Anwar on

Thanks Sharukh for explaining the Mobile detect in PHP. It is very good information.

Shahrukh Khan on

Thank You.

dheerandra kumar on

Shahrukh bhai i really love this site really it’s very helpful for all of us.
thanks shahrukh bhai thanks you so much


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.