Detect iPad and iPhone with PHP
July 25th, 2012
Warning: This post is 12 years old. Some of this information may be out of date.
If you ever have the need to detect iPad and iPhone with PHP, or any other mobile/tablet device, you can use the
excellent php-mobile-detect library available at http://code.google.com/p/php-mobile-detect/.
Example usage:
<?php
require_once "Mobile_Detect.php";
$detect = new Mobile_Detect();
if ($device->isMobile()) {
// code for mobile devices
}
if ($device->isTablet()) {
// code for tablet devices
}
if ($detect->isiOS()) {
// code for iOS devices.
}
if ($detect->isAndroidOS()) {
// code for Android devices.
}
If you want to detect mobile devices but not tablets you can use the following code snippet:
<?php
function is_mobile() {
require_once 'Mobile_Detect.php';
$device = new Mobile_Detect();
if ($device->isMobile()) {
return ($device->isTablet() ? FALSE : TRUE);
}
return FALSE;
}
Previous →
How to find the Magento version