PHP Classes

PHP Mobile Phone Detection: Detect when a site use is using a mobile phone

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 179 All time: 8,727 This week: 63Up
Version License PHP version Categories
phonedetector 1.0.0Custom (specified...7.2HTTP, PHP 5, Wireless and Mobile
Description 

Author

This class can detect when a site user is using a mobile phone.

It can check the user agent string of the current HTTP request to verify if it matches a pattern of one of the well known mobile operating systems.

Currently it can detect the user agent strings of devices using Android or iOS.

Picture of Pierre-Henry Soria
  Performance   Level  
Name: Pierre-Henry Soria <contact>
Classes: 49 packages by
Country: United Kingdom
Innovation award
Innovation award
Nominee: 18x

Winner: 3x

Documentation

? PhoneDetector

Lightweight PHP 7.2 library that detects users' mobile phone based on the device OS.

? Installation (with Composer)

composer require ph-7/phonedetector

? Usage

Below are two simple examples of what you can do with PhoneDetector library.

Example 1

use PierreHenry\PhoneDetector\PhoneDetector;

$phoneDetector = new PhoneDetector();
if ($phoneDetector->isAndroid()) {
    echo 'Your mobile phone is Android!';
}

if ($phoneDetector->isIos()) {
    echo 'Your mobile phone runs with iOS';
}

Example 2

<?php
require 'vendor/autoload.php'; // Include Composer to load the library

use PierreHenry\PhoneDetector\PhoneDetector;

$phoneDetector = new PhoneDetector();

if ($phoneDetector->isAndroid()) {
    $url = 'https://play.google.com/store/apps/details?id=com.lifyzer';
} elseif($phoneDetector->isIos()) {
    $url = 'https://apps.apple.com/app/longer-life-lifyzer-food-scan/id1466196809';
} else {
    $url = 'https://DEFAULT-URL.example';
}

header('Location: ' . $url);

? Author

Pierre-Henry Soria")

[![@phenrysay][twitter-image]][twitter-url]

[Pierre-Henry Soria][author-url], a Passionate, Zen&Cool Belgian Software Engineer :belgium: :chocolate_bar:

? Used By...

I initially created PhoneDetector to redirect users to the correct app's store for https://get.lifyzer.com depending on the mobile device.

https://github.com/Lifyzer/get.lifyzer.com

? Server Requirement

PHP 7.2 or higher.

? License

PhoneDetector library is generously distributed under [MIT License][license-url].

<!-- GitHub's Markdown reference links --> [author-url]: https://pierrehenry.be [license-url]: https://opensource.org/licenses/MIT [twitter-image]: https://img.shields.io/twitter/url/https/shields.io.svg?style=social [twitter-url]: https://twitter.com/phenrysay


  Files folder image Files (6)  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (6)  /  src  
File Role Description
  Plain text file PhoneDetector.php Class Class source

  Files folder image Files (6)  /  tests  
File Role Description
  Plain text file PhoneDetectorTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:179
This week:0
All time:8,727
This week:63Up
User Comments (1)