-3

I want to run some code if the user is not using an apple mobile device browser (iphone, ipad or ipod).

I tried the following but I have no idea if it works:

<?php
if(!strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || !strstr($_SERVER['HTTP_USER_AGENT'],'iPod') || !strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) 
{
     // user is not on an iPhone, iPad, or iPod device so execute code
}
?>
hakre
  • 193,403
  • 52
  • 435
  • 836
user1038814
  • 9,337
  • 18
  • 65
  • 86
  • 3
    http://codereview.stackexchange.com/ – Quentin Jan 23 '12 at 13:09
  • 1
    afaik, the code you posted will work - is there some reason you didn't TIAS before asking? – Chris Browne Jan 23 '12 at 13:10
  • 1
    Hope that you really do care about the device and aren't really looking for Mobile Safari. – Quentin Jan 23 '12 at 16:03
  • possible duplicate of [Is there a way to determine if an iPhone / iPad app is installed?](http://stackoverflow.com/questions/2751640/is-there-a-way-to-determine-if-an-iphone-ipad-app-is-installed) - This might at least partially answer your question and offers more information. – hakre Jan 29 '12 at 11:45

2 Answers2

4

I have used php-mobile-detect and it works very nicely. Can detect all kinds of devices!

Mobile_Detect is a simple PHP class for easy detection of the most popular mobile platforms: Android, iPhone, Blackberry, Opera Mini, Palm, Windows Mobile, as well as generic ones.

hakre
  • 193,403
  • 52
  • 435
  • 836
Adam Fowler
  • 1,750
  • 1
  • 17
  • 18
0

i use this function

if(!function_exists("iOSCheker")) {
    function iOSCheker($var1,$var2) {
        if (ereg('iPhone',$_SERVER['HTTP_USER_AGENT']) || ereg('iPod',$_SERVER['HTTP_USER_AGENT']) || ereg('iPad',$_SERVER['HTTP_USER_AGENT'])) { 
            echo $var1;
        } else {
            echo $var2;
        } 
    }
}
Volodymyr B.
  • 3,369
  • 2
  • 30
  • 48
  • 1
    [`ereg` is depercated](http://stackoverflow.com/questions/5700806/function-eregi-is-deprecated). – hakre Jan 29 '12 at 11:39