Skip to content

๐Ÿ“ฑ Detect the user mobile phone (Android or iOS) based on their device's OS

License

Notifications You must be signed in to change notification settings

pH-7/PhoneDetector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฑ 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 on 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);

โš™ Server Requirement

๐Ÿš€ Author

Pierre-Henry Soria

@phenrysay

Pierre-Henry Soria, a Passionate, Zen&Cool Belgian Software Engineer ๐Ÿ‡ง๐Ÿ‡ช ๐Ÿซ

๐Ÿ˜„ 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

โš– License

PhoneDetector library is generously distributed under MIT License.