PHP Classes


Recommend this page to a friend!
  Classes of Alliaume Hugo  >  PHP Detect Device Type  >  >  Download  
Role: Documentation
Content type: text/plain
Description: Documentation
Class: PHP Detect Device Type
Detect the type of device the user is using
Author: By
Last change: Update
Date: 8 years ago
Size: 1,428 bytes


Class file image Download
[![Build Status](](

DetectDevice is a little (~70 lines), simply, and functional PHP class which detect what kind of device is used to navigate on your website, a pc, a mobile, a tablet or a bot.

How use?
#### Firstly, include DetectDevice class and initialize it
require "class.DetectDevice.php";
$device = new DetectDevice();
// ...

#### Optional : If you want, you can set an other user-agent
$userAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";

// in the constructor
$device = new DetectDevice($userAgent);

// or with the "setUserAgent()" method

#### Use methods to find what kind of device is used
// return a boolean (true or false)
echo $device->isComputer();
echo $device->isMobile();
echo $device->isTablet();
echo $device->isBot();
echo $device->isConsole();

// You can use the "getDeviceType()" to return a string
echo $device->getDeviceType(); // may return "computer", "mobile, "tablet", "bot" or "console"
// ...

#### Or use "is()"
// The "is()" method match $str in UserAgent $str, and return true or false

$str = "msie";

if($device->is($str)) {
    // do stuff for Internet Explorer only

For more information send a message to info at phpclasses dot org.