PHP Classes
elePHPant
Icontem

PHP Detect Device Type: Detect the type of device the user is using

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-05-18 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 810 This week: 4All time: 4,115 This week: 204Up
Version License PHP version Categories
detect-device 5GNU General Publi...5.3HTTP, PHP 5, Wireless and Mobile
Description Author

This class can detect the type of device the user is using.

It can check the user agent header that the user browser is sending to the Web server to determine the type of device associated to that user agent string.

Currently it can detect devices of type computer, tablet, mobile phone or crawler robots.

  Performance   Level  
Name: Alliaume Hugo <contact>
Classes: 2 packages by
Country: France France
Age: ???
All time rank: 239067 in France France
Week rank: 198 Up8 in France France Up

Details
DetectDevice 
============
[![Build Status](https://travis-ci.org/Kocal/DetectDevice.png?branch=master)](https://travis-ci.org/Kocal/DetectDevice)

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
```php
<?php
require "class.DetectDevice.php";
$device = new DetectDevice();
// ...
```

#### Optional : If you want, you can set an other user-agent
```php
<?php
$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
$device->setUserAgent($userAgent);
```

#### Use methods to find what kind of device is used
```php
<?php
// 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()"
```php
<?php
// 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
}

```
  Files folder image Files  
File Role Description
Accessible without login Plain text file .travis.yml Data Auxiliary data
Plain text file class.DetectDevice.php Class Class source
Accessible without login Plain text file DetectDeviceTest.php Test Tests for PHPUnit
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:810
This week:4
All time:4,115
This week:204Up
User Comments (1)
good
3 years ago (Rahul Shambharkar)
80%StarStarStarStarStar