Skip to main content

Tedshd's Dev note

Detect mobile device

Table of Contents

# Detect mobile device

Use PHP or JavaScript detect mobile device like iPhone, iPad, iPod or Android…

## Android

### PHP

<?php
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua, 'android') !== false) {
    echo 'Android!!';
    exit;
}
?>

### JavaScript

var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf("android") > -1) {
    document.write('Android!!');
}

Refer - Android Detection with JavaScript or PHP

## Apple mobile device

Refer - How to detect iPhone, iPod and iPad with PHP Refer - How to Identify an Apple iPhone, iPod or iPad Visitor to Your Website