Amar Banerjee
Amar Banerjee

Reputation: 5012

How to detect whether a site is browsing from IPAD or not

I have a Web Application which is browser compatible made in php and HTML5. I have a certain requirement when a client browse the site from Ipad I want to display different banner.

<?php $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
   if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
$android = '1';

     }
     if(stripos($ua,'iPhone') !== false  || stripos($ua,'iPod') !== false  ||     strstr($ua,'iPhone') || strstr($ua,'iPod')  ) { 

$iPhone = '1';

 }

 ?>

This condition is working for android mobile and other devices but not for Ipad. Does anyone have idea how to detect Ipad device in php.

Upvotes: 2

Views: 1504

Answers (2)

bozdoz
bozdoz

Reputation: 12890

I believe the user agent has 'ipad' in it. Search for ipad.

If you're curious, use a page to spit out the HTTP USER AGENT, and visit with an ipad:

<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

Upvotes: 2

GGio
GGio

Reputation: 7653

    if (preg_match('/ipad/i', $ua)) 
    {
        $platform = 'iPad';
    }

here is what i use for rest of them:

    if (preg_match('/linux/i', $ua)) 
    {
        $platform = 'Linux';
    }
    elseif (preg_match('/ubuntu/i', $ua)) 
    {
        $platform = 'Ubuntu';
    }
    elseif (preg_match('/macintosh|mac os x/i', $ua)) 
    {
        $platform = 'Mac';
    }
    elseif (preg_match('/windows|win32/i', $ua)) 
    {
        $platform = 'Windows';
    }

    if (preg_match('/android/i', $ua)) 
    {
        $platform = 'Android';
    }

    if (preg_match('/palm/i', $ua)) 
    {
        $platform = 'Palm';
    }


    if (preg_match('/iphone/i', $ua)) 
    {
        $platform = 'iPhone';
    }

    if (preg_match('/blackberry/i', $ua)) 
    {
        $platform = 'Blackberry';
    }

    if (preg_match('/ipod/i', $ua)) 
    {
        $platform = 'iPod';
    }

    if (preg_match('/ipad/i', $ua)) 
    {
        $platform = 'iPad';
    }

Upvotes: 5

Related Questions