PHPackages                             pionix-labs/51degrees-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pionix-labs/51degrees-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pionix-labs/51degrees-php
=========================

51Degrees composer package

3.1.7(7y ago)16.3kmpl-2.0PHP

Since Jul 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/pionix-labs/51Degrees-PHP)[ Packagist](https://packagist.org/packages/pionix-labs/51degrees-php)[ RSS](/packages/pionix-labs-51degrees-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

[![51Degrees](https://camo.githubusercontent.com/67ce16d0f57171873038d47c6d75003cb2d80646734fdaaad11263f1631903bc/68747470733a2f2f3531646567726565732e636f6d2f4465736b746f704d6f64756c65732f46696674794f6e652f4469737472696275746f722f4c6f676f2e617368783f75746d5f736f757263653d6769746875622675746d5f6d656469756d3d7265706f7369746f72792675746d5f636f6e74656e743d686f6d652675746d5f63616d706169676e3d6e61746976652d706870 "THE Fastest and Most Accurate Device Detection")](https://camo.githubusercontent.com/67ce16d0f57171873038d47c6d75003cb2d80646734fdaaad11263f1631903bc/68747470733a2f2f3531646567726565732e636f6d2f4465736b746f704d6f64756c65732f46696674794f6e652f4469737472696275746f722f4c6f676f2e617368783f75746d5f736f757263653d6769746875622675746d5f6d656469756d3d7265706f7369746f72792675746d5f636f6e74656e743d686f6d652675746d5f63616d706169676e3d6e61746976652d706870) **Device Detection in Native PHP**

[![Build Status](https://camo.githubusercontent.com/4cc26656b669d7a5d8fe0b83ad34399aec3ffa3bcc957eb76e57358de765d41f/68747470733a2f2f7472617669732d63692e6f72672f63616e6461736d2f3531446567726565732d5048502e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/candasm/51Degrees-PHP)

About
-----

[](#about)

51Degrees for PHP can be installed by composer. Can be used like in basic examples.

Important Information
---------------------

[](#important-information)

Please note that the native PHP API is no longer actively developed. Instead please use the C-Extension or the Cloud Implementation.

Since native PHP is not capable of persistently storing data in memory the API is only capable of working in stream mode which relies on loading the bare minimum of the necessary headers and then using the data file on disk to perform detection. Normally in languages like Java and C# the headers would only be loaded once, upon the application start, and then reused for multiple detections However with native PHP this has to be done for every request which is slow and inefficient.

If you have root access to the server your website/service is running on consider using the C-Extension implementation.

If you are running in an environment with restricted access rights such as a WordPress blog on shared hosting then you should use the Cloud implementation.

This API is still maintained and is in the working order, but maintenance is only limited to bug fixes.

Also please note that the native PHP API requires files of version 3.1.

Installing
----------

[](#installing)

```
composer require pionix-labs/51degrees-php

```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

[basic-usage.php](./examples/basic-usage.php)

```
$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d = $fiftyOneDegrees->getDeviceData();

// Detection results are stored in the $_51d global.
$isMobile = $_51d['IsMobile'];

// Use like:
if ($isMobile) {
    echo "Mobile device.";
} else {
    echo "Non-Mobile device.";
}
```

### Match Metrics

[](#match-metrics)

[match-metrics.php](./examples/match-metrics.php)

```
$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d = $fiftyOneDegrees->getDeviceData();

// Match metrics:
echo "DeviceId: " . $_51d["DeviceId"] . "";
echo "Method: " . $_51d["Method"] . "";
echo "Difference: " . $_51d["debug_info"]["difference"] . "";
```

### Metadata

[](#metadata)

To retrieve description for a particular property: [metadata.php](./examples/metadata.php)

```
$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d_meta_data = $fiftyOneDegrees->getMetadata();

// $_51d_meta_data global contains metadata for properties and values.
// Print description for the IsMobile property.
echo $_51d_meta_data['IsMobile']['Description'];
```

To print all possible values for a chosen property: [metadata-possible-values.php](./examples/metadata-possible-values.php)

```
$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d_meta_data = $fiftyOneDegrees->getMetadata();

// Shows all possible valus for the IsMobile property and a
// description for each value.
echo "";
var_dump($_51d_meta_data['IsMobile']['Values']);
echo "";
```

### Additional Options

[](#additional-options)

51Degrees for PHP allows for some global values to change its behaviour. If not set they will all use default options.

```
$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
/**
 * Controls if property values are set to their typed values or strings.
 * Defaults to TRUE, set to FALSE to disable.
 */
$fiftyOneDegrees->setReturnStrings(true);
// NOTE: Much of the metadata for this property has not been set,
// so you may see strings for things which should not be strings. }

/**
 * Controls which property values should be returned from detection.
 * Greater performance can be gained from a restricted list of properties.
 * By default all values are returned.
 */
 $fiftyOneDegrees->setProperties(['IsMobile', 'HardwareModel', 'PlatformName', 'BrowserName']);
 $_51d = $fiftyOneDegrees->getDeviceData();
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 52.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

2847d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ab2e1e42085c158325e749be03e08430d3d20152186ca36a122c31766b71fb3?d=identicon)[candasm](/maintainers/candasm)

---

Top Contributors

[![candasm](https://avatars.githubusercontent.com/u/1390090?v=4)](https://github.com/candasm "candasm (11 commits)")[![Piran51](https://avatars.githubusercontent.com/u/4609253?v=4)](https://github.com/Piran51 "Piran51 (6 commits)")[![RichTeaMan](https://avatars.githubusercontent.com/u/3968139?v=4)](https://github.com/RichTeaMan "RichTeaMan (4 commits)")

---

Tags

51degrees51degrees-php

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/pionix-labs-51degrees-php/health.svg)

```
[![Health](https://phpackages.com/badges/pionix-labs-51degrees-php/health.svg)](https://phpackages.com/packages/pionix-labs-51degrees-php)
```

###  Alternatives

[markfullmer/dependency_tree

Generate a Composer dependency tree visualization

168.2k](/packages/markfullmer-dependency-tree)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
