2

I am trying to detect the device using this script http://mobiledetect.net/ but it's not detecting iPhone.

header.php:

<?php
require_once 'include/Mobile_Detect.php';
$detect = new Mobile_Detect; ?>

device.php:

<?php include 'include/header.php'; ?>
<?php if( $detect->isMobile() && $detect->isTablet() ){ ?>
<script type='text/javascript'> 
    alert("I am mobile");
</script>
<?php } else { ?>
<script type='text/javascript'> 
    alert("I am desktop");
</script>
<? } ?>

When I check the page on desktop I am getting popup with this message: I am desktop - As I expected

When I check the page on android tablet I am getting popup with this message: I am mobile - As I expected

When I check the page on iPhone I am getting popup with this message: I am desktop - NOT as expected.

Why is this?

Here is the PAGE

Foolish Coder
  • 385
  • 5
  • 20

1 Answers1

0

You're asking whether the browser is running on a mobile device and (&&) on a tablet:

$detect->isMobile() && $detect->isTablet()

Due to the second condition, this is only true for tablets, not for phones. Just remove it if you want the condition to be true for any mobile device:

<?php if( $detect->isMobile() ){ ?>

Pida
  • 928
  • 9
  • 32